Anda di halaman 1dari 5

Jobsheet Praktikum Metode Numerik

Oleh: Nazaruddin, ST. MT


2021

PRAKTIKUM 7
MENYELESAIKAN AKAR PERSAMAAN
DENGAN METODE NEWTON

7.1 TUJUAN
Mempelajari bagaimana cara menyelesaikan akar persamaan dengan metode
Newton

7.2 TEORI DASAR/PROGRAM

1
Jobsheet Praktikum Metode Numerik
Oleh: Nazaruddin, ST. MT
2021

Example

>> x=linspace(-4,4,100);
>> y=x.^2-5;

2
Jobsheet Praktikum Metode Numerik
Oleh: Nazaruddin, ST. MT
2021

>> plot(x,y);grid

% Approximation of a root of a polynomial function p(x)


% Do not forget to enclose the coefficients in brackets [ ]
p=input('Enter coefficients of p(x) in descending order: ');
x0=input('Enter starting value: ');
q=polyder(p); % Calculates the derivative of p(x)
x1=x0-polyval(p,x0)/polyval(q,x0);
fprintf('\n'); % Inserts a blank line
%
% The next function displays the value of x1 in decimal format as indicated
% by the specifier %9.6f, i.e., with 9 digits where 6 of these digits
% are to the right of the decimal point such as xxx.xxxxxx, and
% \n prints a blank line before printing x1
fprintf('The next approximation is: %9.6f \n', x1)
fprintf('\n'); % Inserts another blank line
%
fprintf('Rerun the program using this value as your next approximation \n');

3
Jobsheet Praktikum Metode Numerik
Oleh: Nazaruddin, ST. MT
2021

Setelah dijalankan programnya:

Selanjutnya coba anda kerjakan pogram berikut:


function [fx,dfx]=fungsi2(a,x)
%fungsi untuk menghitung nilai f(x) dan f'(x)
n=size(a,2);
b(1)=a(1);
c(1)=b(1);
for k=2:n-1
b(k)=x*b(k-1)+a(k);
c(k)=x*c(k-1)+b(k);
end;
b(n)=x*b(n-1)+a(k);
fx=b(n);
dfx=c(n-1);

Berikan nama file : fungsi2


Lanjutukan dengan:
%menyelesaikan fungsi F(x)=0 dengan Metode newton
koef=input('masukan vektor koefisien f(x)=');
x=input('masukan nilai taksiran awal x=');
[fx,dfx]=fungsi2(koef,x);
k=1;
hasil1=[];
hasil1(k,1)=x;
hasil1(k,2)=fx;
hasil1(k,3)=-log10(abs(fx));
while abs(fx)>0.000001;
x=x-fx/dfx;
[fx,dfx]=fungsi2(koef,x);
k=k+1;
hasil1(k,1)=x;
hasil1(k,2)=fx;
hasil1(k,3)=-log10(abs(fx));
end;
disp(' x fx -log10(abs(fx))');

4
Jobsheet Praktikum Metode Numerik
Oleh: Nazaruddin, ST. MT
2021

for u=1:k
fprintf('%12.7e %12.7e %12.7e\n',hasil1(u,1),
hasil1(u,2),hasil1(u,3));
end;
%clf;
plot(hasil1(:,3),'g');
xlabel('laju konvergensi f(x)=0')
ylabel('-log10(abs(fx))=0')
hold on;
grid on;

Berikan nama file : latihan1


7.3 SOAL LATIHAN
Soal: Buatlah program untuk mengerjakan soal berikut:
1. Tentukan akar persamaan dengan menggunakan metode Newton Raphson dari persamaan y=x3-
2 , garis memotong kurva pada titik x1=2 dan x2=3. ambil nilai awal xo=2.
2. y=x2 pada titik x1=-4 dan x2=4. ambil nilai awal xo=1.
3. y=x4 - 4x+1 pada titik x1=-4 dan x2=4. ambil nilai awal xo=0.
4. y=x3 - 5 pada titik x1=3 dan x2=4. ambil nilai awal xo=3
5. y=-0.9x2 +1.7 x +2.5 pada titik x1=0 dan x2=8. ambil nilai awal xo=5

7.4 HASIL PEMBAHASAN PROGRAM


(pada bagian ini mahasiswa membuat analisis hasil program yang telah dikerjakan, tulis
dengan tangan)

7.5 KESIMPULAN
(pada bagian ini mahasiswa membuat kesimpulan dari hasil pembahasan, tulis dengan
tangan)

7.6 DAFTAR PUSTAKA


(pada bagian ini mahasiswa membuat daftar pustaka yang digunakan sebagai buku
referensi).

Anda mungkin juga menyukai