Professional Documents
Culture Documents
NIM: C5501122004
Tugas IX Analisa Numerik
a.) Let h = 0.2 and do two steps by hand calculation. Then let h = 0.1 and do four
steps by hand calculation.
b.) Compare the exact solution y(0.4) with the two approximations in part (a).
c.) Does the F.G.E in part (a) behave as expected when h is halved?
3 3t 1
2. y’ = 3y + 3t with y(0) = 1, y(t) = e –t–
4 3
2
3. y’ = -ty with y(0) = 1, y(t) = −e−t / 2
1 1
4. y’ = e-2t- 2y with y(0) = , y(t) = e-2t – te-2t
10 10
Jawab:
function E=euler(f,a,b,ya,M)
%Input - f is the function entered as a string ’f’
%- a and b are the left and right endpoints
%- ya is the initial condition y(a)
%- M is the number of steps
%Output - E=[T’ Y’] where T is the vector of abscissas and
%Y is the vector of ordinates
h=(b-a)/M;
T=zeros(1,M+1);
Y=zeros(1,M+1);
T=a:h:b;
Y(1)=ya;
for j=1:M
Y(j+1)=Y(j)+h*feval(f,T(j),Y(j));
end
E=[T' Y'];
Syntax Eksekusi (disesuakian dengan soal dicontohkan eksekusi no. 1)
clear all
clc
format long
%Input Variable
a=0;
b=0.4;
ya=1;
h1=0.2;
h2=0.1;
M1=(b-a)/h1;
M2=(b-a)/h2;
% M=round(M);
%Mencar error
Error1=abs(yeksak-Y1)
Err1=Error1';
Error2=abs(yeksak2-Y2)
% Mencari Error
% yx_eksak = teksak==1;
% yx_euler = teuler==1;
% datayx_eksak = yeksak(yx_eksak);
% datayx_euler = yeuler(yx_euler);
%Menampilkan tabel 1
tabel1(:,1)=T1;
tabel1(:,2)=Y1;
tabel1(:,3)=Error1;
disp ('Untuk Nilai h=0.2')
fprintf('\n T1 Y1
Error1\n');
disp(tabel1)
%Menampilkan tabel 2
tabel2(:,1)=T2;
tabel2(:,2)=Y2;
tabel2(:,3)=Error2;
disp ('Untuk Nilai h=0.1')
fprintf('\n T2 Y2
Error2\n');
disp(tabel2)
%Membuat Grafik
figure
plot(teksak,yeksak,'b',T1,Y1,'g-.',T2,Y2,'r-.');
legend('f(t,y)','h=0.2','h=0.1','Location','southoutside','O
rientation','horizontal')
hold on
scatter(T1,Y1, 'filled', 'og');
hold on
scatter(T2,Y2, 'filled', 'or');
grid on;
title('Euler')
xlabel('t')
ylabel('y')
Syntax Fungsi
3. function fdif=f(t,y)
f=(-t.*y);
end
Penyelesaian:
By hand
1.) y’ = t2 – y
Diketahui:
a=0
b = 0.4
y(0) = 1 t0 = 0
Maka:
Pada h = 0.2 (2 langkah) Pada h = 0.1 (4 langkah)
t1 = 0.2 t1 = 0.1
y1 = y(0) + h(t02 – y(0)) y1 = y(0) + h(t02 – y(0))
y1 = 1 + 0.2(02 -1) y1 = 1 + 0.1(02 - 1)
y1 = 0.800 y1 = 0.900
t2 = 0.4 t2 = 0.2
y2 = y1 + h(t12 – y1) y2 = y(1) + h(t12 – y(1))
y2 = 0.800+ 0.2(0.22 - 0.800) y2 = 0.900 + 0.1(0.12 – 0.900)
y2 = 0.648 y2 = 0.811
t4 = 0.4
y4 = y(3) + h(t32 – y(3))
y4 = 0.733 + 0.1(0.32 – 0.733)
y4 = 0.66951
By matlab
1. function fdif=f(t,y)
f=(t2-y);
end
2.) y’ = 3y + 3t
Diketahui:
a=0
b = 0.4
y(0) = 1 t0 = 0
Maka:
Pada h = 0.2 (2 langkah) Pada h = 0.1 (4 langkah)
t1 = 0.2 t1 = 0.1
y1 = y(0) + h(3y(0) + 3t(0)) y1 = y(0) + h(3y(0) + 3t(0))
y1= 1 + 0.2(3(1) + 3(0)) y1= 1 + 0.1(3(1) + 3(0))
y1 = 1.60000 y1= 1.30000
t2 = 0.4 t2 = 0.2
y2 = y1 + h(3y(1) + 3t(1)) y2 = y(1) + h(3y(1) + 3t(1))
y2= 1.6 +0.2(3(1.6) + 3(0.2)) y2= 1.3 + 0.1(3(1.3) + 3(0.1))
y2= 2.680000 y2= 1.72000
t4 = 0.4
y4 = y(3) + h(3y(3) + 3t(3))
y4= 2.296 + 0.1(3(2.296) + 3(0.3))
y4 = 3.07480
By matlab
2. function fdif=f(t,y)
f=(3.*y+3.*t);
end
3.) y’ = -ty
Diketahui:
a=0
b = 0.4
y(0) = 1 t0 = 0
Maka:
Pada h = 0.2 (2 langkah) Pada h = 0.1 (4 langkah)
t1 = 0.2 t1 = 0.1
y1 = y(0) + h(-t(0).y(0)) y1 = y(0) + h(-t(0).y(0))
y1= 1 + 0.2(-0 . 1) y1= 1 + 0.1(-0 . 1)
y1 = 1 y1= 1
t2 = 0.4 t2 = 0.2
y2 = y1 + h(-t(1).y(1)) y2 = y(1) + h(-t(1).y(1))
y2= 1 +0.2(-0.2 . 1) y2= 1 + 0.1(-0.1 . 1)
y2= 0.96000 y2= 0.99000
t4 = 0.4
y4 = y(3) + h(-t(3).y(3))
y4= 0.9702 + 0.1(-0.3 + 0.9702)
y4 = 3.07480
By matlab
3. function fdif=f(t,y)
f=(-t.*y);
end
4.) y’ = e-2t- 2y
Diketahui:
a=0
b = 0.4
y(0) = 0.1 t0 = 0
Maka:
Pada h = 0.2 (2 langkah) Pada h = 0.1 (4 langkah)
t1 = 0.2 t1 = 0.1
y1 = y(0) + h(e-2t(0)- 2y(0)) y1 = y(0) + h(e-2t(0)- 2y(0))
y1= 0.1 + 0.2(1 – 2(0.1)) y1= 0.1 + 0.1(1 – 0.2)
y1 = 0.26000 y1= 0.18000
t2 = 0.4 t2 = 0.2
y2 = y1 + h(e-2t(1)- 2y(1)) y2 = y(1) + h(e-2t(1)- 2y(1))
y2= 0.26 +0.2(0.67032 – 2(0.26000)) y2= 0.18 + 0.1(0.45873)
y2= 0.29006 y2= 0.22587
t4 = 0.4
y4 = y(3) + h(e-2t(3)- 2y(3))
y4= 0.24773 + 0.1(0.05335)
y4 = 0.25306
By matlab
4. function fdif=f(t,y)
f=(exp(-2*t)-2*y;
end
5.) y’ = 2ty2
Diketahui:
a=0
b = 0.4
y(0) = 1 t0 = 0
Maka:
Pada h = 0.2 (2 langkah) Pada h = 0.1 (4 langkah)
t1 = 0.2 t1 = 0.1
y1 = y(0) + h(2t(0).y(0)2) y1 = y(0) + h(2t(0).y(0)2)
y1= 1 + 0.2(0 . 1) y1= 1 + 0.1(0 . 1)
y1= 1 y1= 1
t2 = 0.4 t2 = 0.2
y2 = y1 + h(2t(1).y(1)2) y2 = y(1) + h(2t(1).y(1)2)
y2= 1 +0.2(2(0.2) . 1) y2= 1 + 0.1(2(0.1) . 1)
y2= 1.08 y2= 1.02
t4 = 0.4
y4 = y(3) + h(2t(3).y(3)2)
y4= 1.06 + 0.1(2(0.3) . 1.062)
y4 = 1.12741
By matlab
5. function fdif=f(t,y)
f= exp(-2*t)-2*y;
end