Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Loop termination issues' topicStudent Support Forum > General > "Loop termination issues"

Next Comment >Help | Reply To Topic
Author Comment/Response
Sam
10/18/11 10:26pm

Hello

I'm trying to calculate the power of a scattered light beam as a function of the angle away from the normal from a sinusoidal surface according to the equations:

\[Theta][n] = N[ArcSin[(Sin[\[Theta]i] + n*f*\[Lambda])]]
P[n] = N[((2*\[Pi]*a)/\[Lambda])^2*Cos[\[Theta]i]*Cos[\[Theta][n]]]

where \[Theta][n] is the angle of the n'th scattered beam
\[Theta]i is the angle of the primary reflected beam
f is the frequency of light
\[Lambda] is the wavelength of the surface
a is the amplitude of the surface

My loop is:

\[Lambda] = 635*10^-9;
f = 10^4;
a = 10^-9;
\[Theta]i = \[Pi]/4;
\[Theta][0] = \[Theta]i;
\[Theta][0] = \[Theta]i;
For[
n = 1, \[Theta][n] < 20, n++,
\[Theta][n] = N[ArcSin[(Sin[\[Theta]i] + n*f*\[Lambda])]];
P[n] = N[((2*\[Pi]*a)/\[Lambda])^2*Cos[\[Theta]i]*Cos[\[Theta][n]]];
Print["\[Theta]", n, "= ", \[Theta][n], "\nP", n, "= ", P[n],
"\n"]
]
For[
n = -1, \[Theta][n] > -\[Pi]/2, n--,
\[Theta][n] = N[ArcSin[(Sin[\[Theta]i] + n*f*\[Lambda])]];
P[n] = N[((2*\[Pi]*a)/\[Lambda])^2*Cos[\[Theta]i]*Cos[\[Theta][n]]];
Print["\[Theta]", n, "= ", \[Theta][n], "\nP", n, "= ", P[n],
"\n"]
]

When I execute this, I get nothing printed. However, if I change the loop conditions to checking if n<10, 10 results show, each of which has a theta value less than [Pi]/2. I don't see why mathematica doesn't see this in my original loop.

URL: ,

Subject (listing for 'Loop termination issues')
Author Date Posted
Loop termination issues Sam 10/18/11 10:26pm
Re: Loop termination issues Quinn McKinsey 11/26/11 08:22am
Next Comment >Help | Reply To Topic