Picard's Iteration is a way of solving the IVP
$$y'(x)=f(x,y(x)), \quad y(x_0)=y_0 $$
It consists of defining the following sequence of functions recursively:
$$y_0(x):=y_0 \\ y_{n}(x):=y_0+\int_{x_0}^x f(t,y_{n-1}(t)) \mathrm dt.$$
I've tried implementing it in Mathematica, for the particular problem
$$y'=y^2,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