Jumat, 06 April 2012

Metode Numerik


Metode Secant

Listing :
clc;
clear;
disp('Program Metode Secant');
disp('=============================');
E=0.000001;
x0=input('Masukkan X0 :');
xb=input('Masukkan X1 :');
i=0;
M=9;
disp('_______________________________________________');
disp(' i xi f(xi) epsilon');
disp('_______________________________________________');
while (E <M)
fx=exp(x0)-5*x0^2;
fxb=exp(xb)-5*xb^2;
d = xb - (fxb*(xb-x0)/(fxb-fx));
M=abs(x0-xb);
x0 = xb;xb = d;i=i+1;
fprintf('%3.0f %12.6f %12.6f %12.6f\n',i,xb,fx,M);end;disp('_______________________________________________');

 fprintf('Akarnya Adalah = %10.8f\n',xb);
end

Output :


Metode Nweton Raphson
Listing :

function newtonraphson
  clc;
  clear;
  disp('Program Metode Newton Raphson');
  disp('=============================');
  E=0.000001;
  x0=input('Masukkan X awal :');
  i=0;
  M=9;
  xb=0;
  disp('_______________________________________________');
  disp(' i           xi          f(xi)     epsilon');
  disp('_______________________________________________');
  while (E<M)
    fx=exp(x0)-4*x0;
    gx=exp(x0)-4;
    xb=x0-(fx/gx);
    M= abs(x0-xb);
    x0=xb;
    i=i+1;
    fprintf('%3.0f %12.6f %12.6f %12.6f\n',i,xb,fx,M);
  end
  disp('------------------------------')
  fprintf('Akarnya Adalah = %10.8f\n',xb);
end

Output :



Tidak ada komentar:

Posting Komentar