Picard's Iteration is a way of solving the IVP
y′(x)=f(x,y(x)),y(x0)=y0
It consists of defining the following sequence of functions recursively:
y0(x):=y0yn(x):=y0+∫xx0f(t,yn−1(t))dt.
I've tried implementing it in Mathematica, for the particular problem
y′=y2,y(0)=1
as follows
For[{n=0,y[0][x_]:=1},n<10,n++,y[n][x_]:=1+Integrate[y[n-1][t]^2,{t,0,x}]]
which doesn't work at all. What am I doing wrong here, and how can I fix it?
Thank you!
Answer
I believe that the following code does what you want
For[{n = 1, y[0][x_] = 1}, n < 4, n++, y[n][x_] = 1 + Integrate[y[n - 1][t]^2, {t, 0, x}];Print[{n, y[n][t]}]]
Comments
Post a Comment