Contoh Soal :
dy/dx= x√y , y(0) = 1 , x = 0 sampai x = 2 , dengan interval ∆x=0,5
a. Poligon
clear;
clc
disp('=====================================');
disp('dy/dx = x*y^0.5');
disp('y0=1, dx=0.5, x=[0-2]');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.5;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
x2=x+dx/2;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x * ye(i)^0.5;
y1(i+1)=y(i)+fx*dx/2;
fx1= x2 * y1(i)^0.5;
y(i+1)=y(i)+fx1*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
b. Heun
clear;
clc
disp('=====================================');
disp('dy/dx = x + y');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i);
y1(i+1)=y(i)+fx*dx;
fx1= x1 + y1(i);
fxr=(fx+fx1)/2;
y(i+1)=y(i)+fxr*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
Contoh Soal :
dy/dx=x+y , y(0) = 1 , hitung y(0,1) , dengan interval ∆x=0,025
a. Poligon
clear;
clc
disp('=====================================');
disp('dy/dx = x + y');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
x2=x+dx/2;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i);
y1(i+1)=y(i)+fx*dx/2;
fx1= x2 + y1(i);
y(i+1)=y(i)+fx1*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
b. Heun
clear;
clc
disp('=====================================');
disp('dy/dx = x + y');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i);
y1(i+1)=y(i)+fx*dx;
fx1= x1 + y1(i);
fxr=(fx+fx1)/2;
y(i+1)=y(i)+fxr*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
Contoh Soal :
dy/dx=x+y+xy , y(0) = 1 , hitung y(0,1) , dengan interval ∆x=0,025
a. Metode Poligon
clear;
clc
disp('=====================================');
disp('dy/dx = x + y + xy');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
x2=x+dx/2;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i) + x*ye(i);
y1(i+1)=y(i)+fx*dx/2;
fx1= x2 + y1(i) + x2 * y1(i);
y(i+1)=y(i)+fx1*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
b. Heun
clear;
clc
disp('=====================================');
disp('dy/dx = x + y + xy');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i) + x*ye(i);
y1(i+1)=y(i)+fx*dx;
fx1= x1 + y1(i) + x1 * y1(i);
fxr=(fx+fx1)/2;
y(i+1)=y(i)+fxr*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
Contoh Soal :
dy/dx=yx^2-y , y(0) = 1 , x = 0 sampai x = 2, dengan interval ∆x=0,5
(NB : yx^ = yx pangkat 2)
a. Poligon
clear;
clc
disp('=====================================');
disp('dy/dx = yx^2 - y');
disp('y0=1, dx=0.5, x=[0-2]');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.5;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
x2=x+dx/2;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= ye(i)*x^2 - ye(i);
y1(i+1)=y(i)+fx*dx/2;
fx1= y1(i) * x2^2 - y1(i);
y(i+1)=y(i)+fx1*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
b. Heun
clear;
clc
disp('=====================================');
disp('dy/dx = yx^2-y');
disp('y0=1, dx=0.5, interval=[0-2]');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.5;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= ye(i)*x^2 - ye(i);
y1(i+1)=y(i)+fx*dx;
fx1= y1(i)*x1^2 - y1(i);
fxr=(fx+fx1)/2;
y(i+1)=y(i)+fxr*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
dy/dx= x√y , y(0) = 1 , x = 0 sampai x = 2 , dengan interval ∆x=0,5
a. Poligon
clear;
clc
disp('=====================================');
disp('dy/dx = x*y^0.5');
disp('y0=1, dx=0.5, x=[0-2]');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.5;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
x2=x+dx/2;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x * ye(i)^0.5;
y1(i+1)=y(i)+fx*dx/2;
fx1= x2 * y1(i)^0.5;
y(i+1)=y(i)+fx1*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
b. Heun
clear;
clc
disp('=====================================');
disp('dy/dx = x + y');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i);
y1(i+1)=y(i)+fx*dx;
fx1= x1 + y1(i);
fxr=(fx+fx1)/2;
y(i+1)=y(i)+fxr*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
Contoh Soal :
dy/dx=x+y , y(0) = 1 , hitung y(0,1) , dengan interval ∆x=0,025
a. Poligon
clear;
clc
disp('=====================================');
disp('dy/dx = x + y');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
x2=x+dx/2;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i);
y1(i+1)=y(i)+fx*dx/2;
fx1= x2 + y1(i);
y(i+1)=y(i)+fx1*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
b. Heun
clear;
clc
disp('=====================================');
disp('dy/dx = x + y');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i);
y1(i+1)=y(i)+fx*dx;
fx1= x1 + y1(i);
fxr=(fx+fx1)/2;
y(i+1)=y(i)+fxr*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
Contoh Soal :
dy/dx=x+y+xy , y(0) = 1 , hitung y(0,1) , dengan interval ∆x=0,025
a. Metode Poligon
clear;
clc
disp('=====================================');
disp('dy/dx = x + y + xy');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
x2=x+dx/2;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i) + x*ye(i);
y1(i+1)=y(i)+fx*dx/2;
fx1= x2 + y1(i) + x2 * y1(i);
y(i+1)=y(i)+fx1*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
b. Heun
clear;
clc
disp('=====================================');
disp('dy/dx = x + y + xy');
disp('y0=1, dx=0.025, y(0,1)');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.025;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= x + ye(i) + x*ye(i);
y1(i+1)=y(i)+fx*dx;
fx1= x1 + y1(i) + x1 * y1(i);
fxr=(fx+fx1)/2;
y(i+1)=y(i)+fxr*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
Contoh Soal :
dy/dx=yx^2-y , y(0) = 1 , x = 0 sampai x = 2, dengan interval ∆x=0,5
(NB : yx^ = yx pangkat 2)
a. Poligon
clear;
clc
disp('=====================================');
disp('dy/dx = yx^2 - y');
disp('y0=1, dx=0.5, x=[0-2]');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.5;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
x2=x+dx/2;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= ye(i)*x^2 - ye(i);
y1(i+1)=y(i)+fx*dx/2;
fx1= y1(i) * x2^2 - y1(i);
y(i+1)=y(i)+fx1*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');
b. Heun
clear;
clc
disp('=====================================');
disp('dy/dx = yx^2-y');
disp('y0=1, dx=0.5, interval=[0-2]');
disp('=====================================');
a=input('Masukkan nilai a : ');
b=input('Masukkan nilai b : ');
ye(1)=1;
y(1)=1;
dx=0.5;
x1=0;
n=(b-a)/dx;
fprintf('\nJumlah n = %f\n', n);
fprintf('Nilai dx = %f\n\n', dx);
disp('====================================================');
disp('| i | X[i] | YE[i] | Y[i] | E |');
disp('====================================================');
fprintf('|%3d |%8.3f |%8.3f |%8.3f |\n', 1, x1, ye(1), y(1));
for i=1 : n;
x=(i-1)*dx;
x1=x+dx;
ye(i+1)=((y(i)^2)/2)*(x1^3)/3-(y(i)^2)/2;
fx= ye(i)*x^2 - ye(i);
y1(i+1)=y(i)+fx*dx;
fx1= y1(i)*x1^2 - y1(i);
fxr=(fx+fx1)/2;
y(i+1)=y(i)+fxr*dx;
e=((y(i+1)-ye(i+1))/ye(i+1))*100;
fprintf('|%3d |%8.3f |%8.3f |%8.3f |%8.3f |\n', i+1, x1, ye(i+1), y(i+1), e);
end
disp('====================================================');