Legrange's Interpolation
%Program to solve ordinary differential equations using modified Euler's method
clc;
clear;
close;
x0 = 0;
y0 = 1;
h = 0.1; % Step size
xn = 0.1; % Final value
% Define the function y' = f(x,y)
f = @(x,y) -y^2+ x ;
% Implement Euler's modified method
x = x0:h:xn;
y = zeros(size(x));
y(1) = y0;
for i = 2:length(x)
% Predictor step
y(i) = y(i-1) + h*f(x(i-1), y(i-1));
fprintf('Required value by Euler''s method (Predictor method) %f \n :' ,y(i));
%disp(y(i))
x(i)=x(i-1)+h;
y(i,1)=y(i);
% Corrector step
for j=2:20
y(i,j) = y(i-1) + (h/2)*(f(x(i-1), y(i-1)) + f(x(i), y(i,j-1)));
disp(y(i,j));
if abs(y(i,j)-y(i,j-1)) < 0.00001
y(i)=y(i,j);
fprintf('Required value by Euler''s modified method (Corrector
method) %f \n :' , y(i));
break;
end
end
end