Anda di halaman 1dari 4

Contoh Soal 1

Dengan x0=0 dan h=0,05


f(x) = x2+2x+1

Program pada Matlab

clear all;
clc;
disp('Turunan Numerik Aturan Beda');
disp('Contoh Soal 2')
disp('Kelompok 1 - Utia, Rini, M.Ismail')
syms x;
% persamaan diferensial
f=input('Masukkan fungsi f :');
df=diff(f)
%Turunan numerik
xo=0;h=0.05;
f1=subs(f,xo);
f2=subs(f,xo+h);
f3=subs(f,xo-h);
% forward diferensial
FD=(f2-f1)/h
% backward diferensial
BD=(f1-f3)/h
% central diferensial
CD=(f2-f3)/(2*h)
eksak=subs(df,xo)
error1=abs(eksak-FD)
error2=abs(eksak-BD)
error3=abs(eksak-CD)

Output pada Matlab


Turunan Numerik Aturan Beda

Contoh Soal 2

Kelompok 1 - Utia, Rini, M.Ismail

Masukkan fungsi f :x*x+2*x+1

df =

2*x + 2

FD =

41/20

BD =

39/20

CD =
2

eksak =

error1 =

1/20

error2 =

1/20

error3 =

Print screen output Matlab


Contoh Soal 2

Turunkan fungsi dan hitunglah hasil diferensiasi serta bandingkan metode aturan beda maju,
beda pusat dan beda mundur dengan nilai h=0,25 sampai 2,5 dengan selsisih 0,25.
gm gc
v ( t )=
√ c √
tan h
m
t

Program pada Matlab


f = @(t)(sqrt(g*m/c)*tanh(sqrt(g*c/m))*t);
fd = @(x)(sqrt(g*m/c)*tanh(sqrt(g*c/m))*x);
syms x; fdd = diff(fd(x),x); df = inline(fdd);
m = 68.1; t = 10; c = 0.25; g = 9.8; i = 1;
fprintf('I \t\t %.2f \t\t %.2f \t\t %.2f \t\t %.2f \n',i,ff,fc,fb,df(t));

for h=0.25:0.25:2.5
ff = (f(t+h)-f(t))/h;
fc = (f(t+h)-f(t-h))/2*h;
fb = (f(t)-f(t-h))/h;
fprintf('%d \t\t %.2f \t\t %.2f \t\t %.2f \t\t %.2f \n',i,ff,fc,fb,df(t));
i=i+1;
end

Output pada Matlab


>> DNAB2

I 1.00 9.68 60.53 9.68

I 9.68 1 9.68 0.61 9.68 9.68

2 9.68 2.42 9.68 9.68

3 9.68 5.45 9.68 9.68

4 9.68 9.68 9.68 9.68

5 9.68 15.13 9.68 9.68

6 9.68 21.79 9.68 9.68

7 9.68 29.66 9.68 9.68

8 9.68 38.74 9.68 9.68

9 9.68 49.03 9.68 9.68

10 9.68 60.53 9.68 9.68

>>
Print screen output Matlab

Anda mungkin juga menyukai