Hi there!(adsbygoogle = window.adsbygoogle || []).push({});

I am having problem setting up a loop to run my program.

Firstly, i have a DE solved using NDSolve.

solu = NDSolve[{y''[x] == Sin[y[x]], y'[0] == 0, y[0] == a},

y, {x, 0, 2}]

and then to obtain my desired result, i need the initial condition (y[0]==a) to fulfill

(y'[1] /. solu) + ((y[1] /. solu)/3)=0.0001

then I will be given my result, <a>.

I have manually found the result by changing the <a>. But I can’t always depend on this manual method as it is time consuming.

Now I wish to just implement a loop that will automatically generate for <solu> from let say 0 to 1 with 0.01 interval.

I’ve tried using <Catch> <Throw> but it fails. Here’s my code

Catch[

Do[

Print[

solu = NDSolve[{y''[x] == Sin[y[x]], y'[0] == 0, y[0] == a},

y, {x, 0, 2}]];

If[(y'[1] /. solu) + ((y[1] /. solu)/3) < 0.0001, Throw[a]], {a, 0, 1,

0.1}]]

But it fails. It just show a list of 10 NDSolve solutions without the <a> thrown out.

I try again with <For> but it is even worse, I can’t even let the thing run.

Please help me with this. Thank you very much.

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Mathematica loop problem.

Loading...

Similar Threads - Mathematica loop problem | Date |
---|---|

Mathematica While Loop in Mathematica | Feb 25, 2018 |

Mathematica For looping problem not getting answer | May 24, 2017 |

Mathematica: Getting part of a list, lithin a loop. | Dec 6, 2014 |

Mathematica: Problem with For loop increments | Jul 5, 2012 |

For Loop Problem in Mathematica | May 19, 2009 |

**Physics Forums - The Fusion of Science and Community**