Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

UTS METODE NUMERIK

JAWABAN 1. A didapatkan solusi solusi x*= -2.76214


%metode newton raphson
clc;
clear;
awal = input('masukkan nilai awal');
x = awal;
f=@(x) 2*x^3+5*x^2+4;
y=@(x) 6*x^2+10*x;
disp(['iter-| x1 | x2 | kesalahan'])
for i=1:100
x2 = x-(f(x)/y(x));
error = abs(x x2);
iter(i)= i;
Error(i) = error;
if error <= 1e-5
disp(['*'])
fprintf('%3d %1.8f %1.8f %1.8f\n',i,x,x2,error)
break
else
fprintf('%3d %1.8f %1.8f %1.8f\n',i,x,x2,error)
end
x = x2;
end
plot(iter,Error,'b-o','MarkerFaceColor','y')
title('f(x)=2*x^3+5*x^2+4')
ylabel('Error'), xlabel('Iterasi ke')
grid on

grafik
JAWABAN 1.B didapatkan solusi x*= -4.2737

%metode Secant
clear all;
clc;
f=@(x) x^3+4*x^2+5
xo=-5;
x1=-4;
for i=1:150
f(xo);
f(x1);
x2=x1-(f(x1)*(x1-xo)/((f(x1)-(f(xo)))));
kes=abs(x2-x1);
xo=x1;
x1=x2;
fprintf('%3d %9.5f %9.6f \n',i,x2,kes)

plot(i,kes,'ro','MarkerFaceColor','y','LineWidth',i)
xlabel('Iterasi Ke')
ylabel('kesalahan')
title('f(x)=x^3+4*x^2+5')
hold on
grid on
if kes<=10^-5
break
else
end
end
text(7,2,strcat('X*= ',num2str(x2)))
legend('kesalahan')

Grafik
Soal no 1.c didapatkan x*=3.63198
%newton raphson
clc;
clear;
awal = input('masukkan nilai awal');
x = awal;
f=@(x) x^3-2*x^2-4*x-7;
y=@(x) 3*x^2-4*x-4;
disp(['iter-| x1 | x2 | kesalahan'])
for i=1:100
x_now = x-(f(x)/y(x));
error = abs(x - x_now);
iter(i)= i;
Error(i) = error;
if error <= 1e-5
disp(['*'])
fprintf('%3d %1.8f %1.8f %1.8f\n',i,x,x_now,error)
break
else
fprintf('%3d %1.8f %1.8f %1.8f\n',i,x,x_now,error)
end
x = x_now;
end

plot(iter,Error,'b-o','MarkerFaceColor','y')
title('f(x)=x^3-4*x^2-9*x-7')
ylabel('Error'), xlabel('Iterasi ke')
grid on

grafik
Soal no 1.d didapatkan x*= -1.3781
%REGULA FALSI
clc;
clear all;
x0=input ('input X0 ');
x1=input ('input X1 ');
f=@(x) 3*x^3-x^2-2*x+7;
disp(['KE- | x0 | x1 | x2 | ERROR'])
for i=1:100
x2= x0-(f(x0)*(x1-x0))/(f(x1)-f(x0));
error = abs(x2-x1);
iter(i)= i;
Error(i) = error;
if error <= 1e-5
fprintf('%3d %2.5f %2.5f %2.5f %2.8f\n',i,x0,x1,x2,error)
break
else
fprintf('%3d %2.5f %2.5f %2.5f %2.6f\n',i,x0,x1,x2,error)
end
x0 = x1;
x1 = x2;
end
plot(iter,Error,'b-o','MarkerFaceColor','y')
title('f(x)= 3*x^3-x^2-2*x+7')
ylabel('Error'), xlabel('Iterasi ke')
grid on

grafik
Soal no 1.e didapatkan x*= 5.7700362

%metode newton raphson


clc;
clear;
awal = input('masukkan nilai awal');
x = awal;
f=@(x) x^3-4*x^2-9*x-7;
y=@(x) 3*x^2-8*x-9;
disp(['iter-| x1 | x2 | kesalahan'])
for i=1:100
x2 = x-(f(x)/y(x));
error = abs(x - x2);
iter(i)= i;
Error(i) = error;
if error <= 1e-5
disp(['*'])
fprintf('%3d %1.8f %1.8f %1.8f\n',i,x,x2,error)
break
else
fprintf('%3d %1.8f %1.8f %1.8f\n',i,x,x2,error)
end
x = x2;
end

plot(iter,Error,'b-o','MarkerFaceColor','y')
title('f(x)= x^3-4*x^2-9*x-7)
ylabel('Error'), xlabel('Iterasi ke')
grid on

Grafik
2.Hasil Script Matlab
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

b =

10 18 3 10 -15

B2-1.5B1

U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10
3
3
10
-15

B3-0.5B1

U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10
3
-2
10
-15

B4-2B1
U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10
3
-2
-10
-15

B5-1B1

U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10
3
-2
-10
-25

B3--0.6B2

U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10.0000
3.0000
-0.2000
-10.0000
-25.0000

B4-2.8B2
U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10.0000
3.0000
-0.2000
-18.4000
-25.0000

B5-2.4B2

U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10.0000
3.0000
-0.2000
-18.4000
-32.2000

B4-1.5B3

U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10.0000
3.0000
-0.2000
-18.1000
-32.2000

B5-2B3
U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


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

ans =

10.0000
3.0000
-0.2000
-18.1000
-31.8000

B5-1.3577B4

U =

2.0000 3.0000 -1.0000 1.0000 -2.0000


0 -2.5000 2.5000 -3.5000 5.0000
0 0 -2.0000 -4.6000 3.0000
0 0 0 13.7000 -11.5000
0 0 0 0 3.6131

ans =

10.0000
3.0000
-0.2000
-18.1000
-7.2263

x =

2.0000
3.0000
4.0000
-3.0000
-2.0000
UTS PRAKTIK METODE NUMERIK

Oleh :
RIAN PRATAMA
GEOFISIKA SEMESTER 4
31.15.0025

SEKOLAH TINGGI METEOROLOGI KLIMATOLOGI DAN GEOFISIKA


TANGERANG SELATAN
2017

You might also like