Example 08
The Do Command
GIVEN: A First Order ODE
y'=f(x,y)=-y+sinx
x0=0
y0=1
REQUIRED: Solve using the Euler's approximation.
SOLUTION:Generate example08.nb
Clear[f, x, y];
f[x_, y_] = -y + Sin[x];
x0=0;
y0= 1;
h = 0.01;
n=10;
x=x0;
y=y0;
output = {{x, y}};
Do[y=y+h*f[x, y];
x = x + h;
output = Append[output, {x, y}], {i, 1, n}];
ListPlot[output, PlotJoined -> True];
Example
Homework:
Change the initial condition
Please send questions or suggestions about this web page to beatnic@aset.psu.edu
ASET | ITS | Penn State
|