Anda di halaman 1dari 10

Nama : Ida Bagus Gauttama Bhara Dwaja

NPT : 11.15.0015

Kelas : Meteorologi 4A

1. Script Matlab dan Grafik

a. f(x) = 2x3 + 5x2 + 4

disp('Metode Bisection')

f=@(x) 2*x^3 + 5*x^2 + 4


a=-1;% batas atas
b=-3;% batas bawah

for i=1:1000000
c=(a+b)/2;
f(a);
f(b);
f(c);
kes=abs(a-b);
e=10^-5;
iter(i)=i;
kesa(i)=kes;
fprintf('%3d %9.5f %9.6f \n',i,c,kes)
if kes<=e
break
else
if f(a)*f(c)<0
b=c;
else
a=c;
end
end
end

plot(iter,kesa,'-
ko','markerfacecolor','r','linewidth',1,'markeredgecolor','k')
title('Metode Bisection')
xlabel('Iterasi')
ylabel('Kesalahan')
grid on
legend('Error')
b. f(x)= x3 + 4x2 + 5

disp('Metode Regular Falsi')

f=@(x) x^3 + 4*x^2 + 5


a=-3;
b=-5;

for i=1:100
c=b-(((b-a)*f(b)/(f(b)-f(a))));
f(a);
f(b);
f(c);
kes=abs(f(c));
iter(i)=i;
kesa(i)=kes;
fprintf('%3d %9.5f %9.6f \n',i,c,kes)
if f(a)*f(c)<0
b=c;
else
a=c;
end
if kes<10^-5
break
else
end
end

plot(iter,kesa,'-
ko','markerfacecolor','r','linewidth',1,'markeredgecolor','k')
title('Metode Regular Falsi')
xlabel('Iterasi')
ylabel('Kesalahan')
grid on
legend('Error')

c. f(x) = x3 - 2x2 - 4x 7

disp('Metode Iterasi Sederhana')

fi=@(x) sqrt((4*x+7)/(x-2));%rumus x baru yang akan dicari dari nilai


x lama yang telah ditentukan)
xo=3;%nilai x awal

for i=1:100
fi(xo);
kes=abs(xo-fi(xo));
fprintf('%3d %9.5f %9.6f \n',i,xo,kes)
xo=fi(xo);
iter(i)=i;
kesa(i)=kes;
if kes<=10^-5
break
else
end
end

plot(iter,kesa,'-
ko','markerfacecolor','r','linewidth',1,'markeredgecolor','k')
title('Metode Iterasi Sederhana')
xlabel('Iterasi')
ylabel('Kesalahan')
grid on
legend('Error')

d. f(x) = 3x3 - x2 - 2x + 7

disp('Metode Secant')

f=@(x) 3*x^3-x^2-2*x+7;
Xo=-1;%batas bawah nilai X
X1=-3;%batas atas nilai X

for i=1:100
f(Xo);
f(X1);
X2=X1-(f(X1)*(X1-Xo)/((f(X1)-(f(Xo)))));
er=abs(X2-X1);%erorr atau kesalahan
ulang(i)=i;
error(i)=er;
fprintf('%2d %7.5f %7.6f \n',i,X2,er)
Xo=X1;
X1=X2;
if er<=10^-5
break
else
end
end

plot(ulang,error,'-
ko','markerfacecolor','r','markeredgecolor','k','linewidth',1)
title('Metode Secant')
xlabel('Iterasi')
ylabel('Kesalahan')
grid on
legend('Error')

e. f(x) = x3 - 4x2 - 9x 7

disp('Metode Secant')

f=@(x) x^3-4*x^2-9*x-7; %fungsi


Xo=4; %batas bawah nilai X
X1=6; %batas atas nilai X

for i=1:100
f(Xo);
f(X1);
X2=X1-(f(X1)*(X1-Xo)/((f(X1)-(f(Xo)))));
er=abs(X2-X1);%erorr atau kesalahan
ulang(i)=i;
error(i)=er;
fprintf('%2d %7.5f %7.6f \n',i,X2,er)
Xo=X1;
X1=X2;
if er<=10^-5
break
else
end
end

plot(ulang,error,'-
ko','markerfacecolor','r','markeredgecolor','k','linewidth',1)
title('Metode Secant')
xlabel('Iterasi')
ylabel('Kesalahan')
grid on
legend('Error')

2. Hasil Script step-by-step metode eliminasi Gauss

Sistem Persamaan Linear A.x=b


Matriks A=[2 3 -1 1 -2; 3 2 1 -2 2; 1 3 -4 -2 -1; 4 -1 2 -1 3; 2 -3 1 2 4]

A=

2 3 -1 1 -2
3 2 1 -2 2
1 3 -4 -2 -1
4 -1 2 -1 3
2 -3 1 2 4
Matriks b=[10 18 3 10 -15]
b=
10
18
3
10
-15

Matriks =

2 3 -1 1 -2 10
3 2 1 -2 2 18
1 3 -4 -2 -1 3
4 -1 2 -1 3 10
2 -3 1 2 4 -15

Baris 2 - 1.5 Baris 1

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
1.0000 3.0000 -4.0000 -2.0000 -1.0000 3.0000
4.0000 -1.0000 2.0000 -1.0000 3.0000 10.0000
2.0000 -3.0000 1.0000 2.0000 4.0000 -15.0000

Baris 3 - 0.5 Baris 1

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 1.5000 -3.5000 -2.5000 0 -2.0000
4.0000 -1.0000 2.0000 -1.0000 3.0000 10.0000
2.0000 -3.0000 1.0000 2.0000 4.0000 -15.0000

Baris 4 - 2 Baris 1

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 1.5000 -3.5000 -2.5000 0 -2.0000
0 -7.0000 4.0000 -3.0000 7.0000 -10.0000
2.0000 -3.0000 1.0000 2.0000 4.0000 -15.0000

Baris 5 - 1 Baris 1

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 1.5000 -3.5000 -2.5000 0 -2.0000
0 -7.0000 4.0000 -3.0000 7.0000 -10.0000
0 -6.0000 2.0000 1.0000 6.0000 -25.0000

Baris 3 - -0.6 Baris 2

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 0 -2.0000 -4.6000 3.0000 -0.2000
0 -7.0000 4.0000 -3.0000 7.0000 -10.0000
0 -6.0000 2.0000 1.0000 6.0000 -25.0000

Baris 4 - 2.8 Baris 2


Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 0 -2.0000 -4.6000 3.0000 -0.2000
0 0 -3.0000 6.8000 -7.0000 -18.4000
0 -6.0000 2.0000 1.0000 6.0000 -25.0000

Baris 5 - 2.4 Baris 2

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 0 -2.0000 -4.6000 3.0000 -0.2000
0 0 -3.0000 6.8000 -7.0000 -18.4000
0 0 -4.0000 9.4000 -6.0000 -32.2000

Baris 4 - 1.5 Baris 3

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 0 -2.0000 -4.6000 3.0000 -0.2000
0 0 0 13.7000 -11.5000 -18.1000
0 0 -4.0000 9.4000 -6.0000 -32.2000

Baris 5 - 2 Baris 3

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 0 -2.0000 -4.6000 3.0000 -0.2000
0 0 0 13.7000 -11.5000 -18.1000
0 0 0 18.6000 -12.0000 -31.8000

Baris 5 - 1.3577 Baris 4

Matriks =

2.0000 3.0000 -1.0000 1.0000 -2.0000 10.0000


0 -2.5000 2.5000 -3.5000 5.0000 3.0000
0 0 -2.0000 -4.6000 3.0000 -0.2000
0 0 0 13.7000 -11.5000 -18.1000
0 0 0 0 3.6131 -7.2263

Solusi sistem Persamaan linear :


2.0000
3.0000
4.0000
-3.0000
-2.0000

Anda mungkin juga menyukai