2
$\begingroup$

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 equations (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.

$\endgroup$
4
$\begingroup$

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]];
$\endgroup$
  • $\begingroup$ Yes! Seems like it! Thank you very much! $\endgroup$ – May Mar 29 '13 at 14:49
  • 1
    $\begingroup$ Is , iteration 0.1 doing anything here? $\endgroup$ – Mr.Wizard Mar 29 '13 at 19:26
  • $\begingroup$ sure, I meant iteration = 0.1. And all that is of course a quick schematic sketch. Just excercising quick understanding and answering. $\endgroup$ – Rolf Mertig Mar 29 '13 at 21:48
0
$\begingroup$

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; σ = 0; While[σ <1, 
     σ = σ + iteration; Print[σ]; 
     If[σ < 0.5, iteration = 0.05, iteration = 0.1]];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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