Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'd like to know if there is a possibility to solve an equation in a while loop with 2 different steps. I want the step to be small at the beginning and bigger after a certain value of sigma (sigma is the parameter that changes). I don't have an exemple and didn't find anything near it here. It would look like :

If[sigma<0.5,iteration=0.05 Then[While[Solve[hat==0, x], Else[While[Solve[hat==0, x], with iteration 0.1]]]

"hat" is a system of equation (long to obtain and I can't copy everything); I want to know if it is possible, otherwise I'll just put the results together on a plot. Thanks!

share|improve this question

2 Answers 2

Yes. E.g.:

   iteration = 0.1; j = 0; sigma = 1;
   While[j < 0.3,
   j = j + iteration;
  If[j > .1, sigma = 0];
  Print[j];
  If[sigma < 0.5, iteration = 0.05, iteration = 0.1]];
share|improve this answer
    
Yes! Seems like it! Thank you very much! –  May Mar 29 '13 at 14:49
1  
Is , iteration 0.1 doing anything here? –  Mr.Wizard Mar 29 '13 at 19:26
    
sure, I meant iteration = 0.1. And all that is of course a quick schematic sketch. Just excercising quick understanding and answering. –  Rolf Mertig Mar 29 '13 at 21:48

Actually, I didn't need the first "If" and j, because the second gives the condition if sigma<0.5 : iteration = 0.1, else sigma>0.5 : iteration = 0.05 :

    iteration = 0.1; \[Sigma] = 0; While[\[Sigma] <1, 
     \[Sigma] = \[Sigma] + iteration; Print[\[Sigma]]; 
     If[\[Sigma] < 0.5, iteration = 0.05, iteration = 0.1]];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.