You are on page 1of 1

function [ ] = euler_test( );

h=input('entrer valeur du pas:');

[x1, y1] = Progressive(0, -1,h , 20);

[x2, y2] = Regressive(0, -1, h, 20);

x3 = 0:0.1:5;
y3 = 1./(exp(-x3) - x3.^2 + 2.*x3 - 2);

axis([0, 5, -1.8, 0]);


plot(x1, y1, 'r--o');
hold on;
plot(x2, y2, 'g--o');
hold on
plot(x3, y3);
end

function [ t, y ] = Regressive( x0, y0, h, N )

i = 1;
t(i) = x0;
y(i) = y0;

for i = 1 : N
y(i + 1) = (1 - h - sqrt((1 - h)^2 - 4*h*(t(i) + h)^2*(y(i))))/(2*h*(t(i) +
h)^2);
t(i + 1) = t(i) + h;
i = i + 1;
end

end

function [ t, y ] = Progressive( t0, y0, h, N )


i = 1;
t(i) = t0;
y(i) = y0;

for i = 1 : N
y(i + 1) = y(i) + h * f(t(i), y(i));
t(i + 1) = t(i) + h;

i = i + 1;
end

end
function [ x ] = f( t, y )
x = y + (t^2) * (y^2);

end

You might also like