+ Reply to Thread
Results 1 to 4 of 4

Nested if error

  1. #1
    Registered User
    Join Date
    11-11-2007
    Posts
    1

    Nested if error

    I am programming vector calculator and it needs to test for a certain set of conditions. I thought maybe someone familiar with this kind of statement could give me a little feedback.

    Here is what I have so far (2 conditions):

    =IF(D9>90, D8*COS(D9-90)*PI()/180, IF(D9>180,D8*COS(D9-180)*PI()/180, D8*COS(D9)*PI()/180))

    The 2 conditions are to subtract 90 from d9 if its greater then 90 (within the formula and then the subtract 180 from D9 if it is greater then 180 else just do the normal formula.
    Maybe there is something obvious I am missing. Any feedback would be greatly appreciated.
    thank you very much.

  2. #2
    Forum Contributor
    Join Date
    10-30-2007
    Location
    Norway
    MS-Off Ver
    MS Office 2007
    Posts
    345
    You have to start checking for the largest condition first ( >180). If you run this formula for a test value of 200 in your formula this will be catched by the >90 condition. This is because 200 is larger than 90 and the first condition will be true.

    Or try using this formula. Should give you the same result as your IF formula:

    =D8*COS(MOD(D9,90))*PI()
    Last edited by Bjornar; 11-11-2007 at 02:57 PM.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    I'd put the IF within the generic calculation, thus avoiding repeating it 3 times, i.e. your calculation is just

    =D8*COS(x)*PI()/180

    where x is the variable value represented by

    =D9-IF(D9>180,180,IF(D9>90,90,0))

    ...so combine the two to get

    =D8*COS(D9-IF(D9>180,180,IF(D9>90,90,0)))*PI()/180

  4. #4
    Forum Contributor
    Join Date
    10-30-2007
    Location
    Norway
    MS-Off Ver
    MS Office 2007
    Posts
    345
    I see now that you may have another error in your calculation. That is not with the IF function but with the COS function. I'm not exacly aware of what you are trying to calculate but as COS function uses radians instead of degree i tought maybe it could be more than the IF function that was your problem.

    Instead of:

    =D8*COS(x)*PI()/180

    Maybe you should use:

    =D8*COS(x*PI()/180)
    or
    =D8*COS(RADIANS(X))

    Try this instead of your whole IF problem formula:

    =D8*COS(RADIANS(MOD(D9,90)))

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1