Consider the differential equation dy / dx = 2x, with initial condition y(0) = 1
ID: 1891599 • Letter: C
Question
Consider the differential equation dy / dx = 2x, with initial condition y(0) = 1. Use Euler's method with two steps to estimate y when x = 1: u(1) (Be sure not to round your calculations at each step!) Now use four steps: y(1) (Be sure not to round your calculations at each step!) What is the solution to this differential equation (with the given initial condition)? y = What is the magnitude of the error in the two Euler approximations you found? Magnitude of error in Euler with 2 steps = Magnitude of error in Euler with 4 steps = By what factor should the error in these approximations change (that is, the error with two steps should be what number times the error with four)? factor = (How close to this is the result you obtained above?)Explanation / Answer
y'=f(x,y), y(x0) =y0 y'= y-x^2+1;, y(0) =1/2 function y x=f(x,y) yx= y-x^2+1; %% Euler metodu clear all for k=1:2 h=0.2/ 2^(k-1); tmax=2; n=tmax /h; x(1)= 0; y(1)= 1/2; true(1) = 1/2; ero(1) =0; disp( ' x numerical gercek hata ' ) disp( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' ) for i=1:(n + 1 ) x(i+1) = x(1)+ i*h; y(i+1) = y(i) + h*f(x(i), y(i)); true(i+1) = -0.5*exp(x(i)) + (x(i)+1)^2; ero(i+1) =abs( y(i) - true(i+1) ); if mod(i-1,2^(k-1))==0 fprintf( '%5.2f%17.7f%19.7f%19.7e ' ,x(i),true(i+1),y(i), ero(i+1) ); end end end x numerical gercek hata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0.00 0.5000000 0.5000000 0.0000000e+000 0.20 0.8292986 0.8000000 2.9298621e-002 0.40 1.2140877 1.1520000 6.2087651e-002 0.60 1.6489406 1.5504000 9.8540600e-002 0.80 2.1272295 1.9884800 1.3874954e-001 1.00 2.6408591 2.4581760 1.8268309e-001 1.20 3.1799415 2.9498112 2.3013034e-001 1.40 3.7324000 3.4517734 2.8062658e-001 1.60 4.2834838 3.9501281 3.3335566e-001 1.80 4.8151763 4.4281538 3.8702251e-001 2.00 5.3054720 4.8657845 4.3968745e-001 x numerical gercek hata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0.00 0.5000000 0.5000000 0.0000000e+000 0.20 0.8292986 0.8140000 1.5298621e-002 0.40 1.2140877 1.1815400 3.2547651e-002 0.60 1.6489406 1.5970634 5.1877200e-002 0.80 2.1272295 2.0538467 7.3382822e-002 1.00 2.6408591 2.5437545 9.7104562e-002 1.20 3.1799415 3.0569430 1.2299856e-001 1.40 3.7324000 3.5815010 1.5089902e-001 1.60 4.2834838 4.1030162 1.8046758e-001 1.80 4.8151763 4.6040496 2.1112666e-001 2.00 5.3054720 5.0635000 2.4197192e-001 >>