You are on page 1of 2

clc

close all
clear all
a=0;
b=1;
h=0.2;
f=inline('y-x^2+1');
A=zeros(1,9);
A(1,2)=0; %x0
A(1,3)=0.5; %y0
x=a:h:b;
l=length(x)-1;
for i=1:l
A(i,1)=i-1;
A(i,4)=h*f(A(i,2),A(i,3)); %k1
A(i,5)=h*f(A(i,2)+h/2,A(i,3)+A(i,4)/2); %k2
A(i,6)=h*f(A(i,2)+h/2,A(i,3)+A(i,5)/2); %k3
A(i,7)=h*f(A(i,2)+h,A(i,3)+A(i,6)); %k4
A(i,8)=A(i,3)+(1/6)*(A(i,4)+2*(A(i,5)+A(i,6))+A(i,7)); %y1
A(i,9)=A(i,2)+h; %xn+1
A(i+1,2)=A(i,9);
A(i+1,3)=A(i,8);
end
display(A)

clc
clear
f=inline('2*x^2-4*x-5');
a=2
b=3
e=0.00001;
c=(a+b)/2;
while abs(f(c))>e
c=(a+b)/2;
if f(a).f(c)<0
b=c;
else
a=c;
end
end

clc
clear
syms x1 x2 x3
x1=0;
x2=0;
x3=0;
A=zeros(1,4);
for i=1:10
x1=(7+A(i,3)-A(i,4))/4;
x2=(21+4*A(i,2)+A(i,4))/8;
x3=(15+2*A(i,2)-A(i,3))/5;
A(i+1,:)=[i,x1,x2,x3];
end
A

You might also like