Message Boards Message Boards

2 Replies
2 Total Likes
View groups...
Share this post:

While loop syntax in Mathematica 9

Posted 11 years ago
Hi There,

I am trying to write a loop that will carry out a series of individual calculations iteratively. The loop will need to be something like a DoWhile so that I can run once completely through before I check the test statement. Pseudo code is below.

 //Define constants
 x=0.055 Degree; Epsilon = 0.001; sightd = 100; delta = 0.0005 Degree;
 Start loop here
 //Compute solution to equation once first
 test statement //to be checked starting second iteration
angsol = NDSolve[Equations]

//set new function to solution of NDSOLVE

In[267]:= xang[t_] := xa[t] /. angsol[[1, 1]]

//Find critical value

In[269]:= tang = FindRoot[xang[t] == sightd, {t, 0.1}];


In[265]:= x = x + delta;

Restart Loop

Does anyone have any suggestions? I know steps work individually, but now I need to string them together so the program will loop and find the solution.

Thanks in advance

POSTED BY: Cole Pierson
2 Replies
I might be misunderstanding your description, but this seems like a problem well-suited for Nest or NestWhile.
POSTED BY: Richard Hennigan
Posted 11 years ago
Update:: Solved

I was able to solve this using a compound expression (;) inside a while loop structure. I had to change my check statement to prevent an infinite loop, but added an if statement break.

POSTED BY: Cole Pierson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract