- #1
DarkForXe
- 8
- 0
Hi there!
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.
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.