Q:

Matlab composite 'if' statement not giving expected result

While writing a program for equation (5) from this paper http://adsabs.harvard.edu/abs/1992PASJ...44..493K,
 
I think I have made some mistake (below). I don't know how to include the 'or' from the equation.
    if alpha_sgp<alpha<=(alpha_sgp-180)
        if p<=180-t
          P=p+t;
        else %p>180-t
          P=p+t-180;
        end
    elseif alpha<=alpha_sgp | (alpha_sgp-180)<alpha   
        if p>=t
          P=p-t;
        else %p<t
          P=p-t+180;
        end
    end

Any help will be much appreciated.

A:

I think there is a problem with your statement:
if alpha_sgp<alpha<=(alpha_sgp-180)

While this is syntactically correct in Matlab, it's not doing what you think it is.
Simple example:
a=1;b=2;c=3;
disp(a<b<c)

Will return 1 (true). BUT
disp(a<c<b)

Will ALSO return 1. This has to do with order of operations, and the fact that a sub-expression of the type a<b will be evaluated (to 1), before the result is compared to c. Thus
a<b<c

Is equivalent to
(a<b) < c

Is equivalent to
If ( (a < b) & (1 < c)) | ( (a >= b ) & (0 < c) )

What you actually want as your first line is
(alpha_sgp<alpha) & (alpha<=(alpha_sgp-180))

Quite apart from making sure that you do the conversions from degrees to radians right, etc. I recommend that you stick to radians - using the built in pi - rather than working in degrees, and having to use functions like sind instead of sin.
Also - you make a curious comment about "not knowing how to include for" - when there is no for, just an or in the equation. Could this be a typo on your part?
Finally - note that the second set of conditions are basically the inverse of the first - when (alpha_sgp < alpha) & (alpha <= (alpha_sgp-180)) is false, then the converse is true. So in implementing your formula, you can replace the whole elseif line with just else.
Feel free to comment if you need further clarification.

