Sabtu, 26 Juni 2010

VISUALISASI AKAR POLINOMIAL DENGAN 
METODE REGULA FALSI 
Source code diimplementasikan dengan matlab 7.0 
while 1
clear, clf,clc
fprintf( '\n=============================================' ); 
   fprintf( '\n     VISUALISASI AKAR PERSAMAAN POLINOMIAL   ' ); 
   fprintf( '\n                 menggunakan              ' );
   fprintf( '\n             METODE REGULA FALSI           ' );     
   fprintf( '\n        oleh : FEBRIYANTO                  ' );
   fprintf( '\n       fungsi f(X) disimpan di fcn.m       ' );
   fprintf( '\n============================================= \n' ); 
      x0 = input ('input tebakan x0  : ');
      x1 = input ('input tebakan x1  : ');
      fprintf(' nilai f(x0)=%10g',fcn(x0));
      fprintf('\n nilai f(x1)=%10g ',fcn(x1));
      d=fcn(x0)*fcn(x1);
      fprintf('\n nilai fcn(x0)*fcn(x1) %10g',d);
      if (d< 0);
      maxerror = input('\n input nilai error: ');
       maxit = input('input N max      : ');
      fplot('fcn',[-10 10]); grid on; hold on;
xlabel('SUMBU X');
ylabel('SUMBU Y');
title('VISUALISASI AKAR DENGAN METODE REGULA FALSI');
count = 0;         
rel_error = 1;     
c = x1;           
fprintf(1,'\n============================================================================'); 
fprintf('\n  No_ITerasi        X0               X1              Xr             error\n');
while (rel_error > maxerror) & (count < maxit)
  count = count + 1;
  xrold = c;
  c = x1 - fcn(x1)*(x1-x0)/(fcn(x1)-fcn(x0));
  plot(c,fcn(c),'ro');

  if c ~= 0
    rel_error = abs((c - xrold)/c) * 100;
  end
    fprintf('%3g           %10g     %10g      %10g         %10.4f\n',count,x0,x1,c,rel_error)
    test = fcn(x0) * fcn(c); 
    if test == 0
    rel_error = 0;
  elseif test < 0
    x1 = c;       
  else
    x0 = c;       
  end
end
fprintf(1,'\n============================================================================ \n'); 
fprintf(1,'                  Hasilnya (x)     :%10g   \n',c) ;
fprintf(1,'                dengan toleransi   :%10.4f \n',rel_error) ;
fprintf(1,'                  dengan iterasi   :  %3g   \n',count) ;
if rel_error>maxerror
    fprintf(1,'                                 Proses  GAGAL  \n') ;
else
    fprintf(1,'                                 Proses  SUKSES  \n') ;
end
fprintf(1,'=============================================================================');
 kont1 = input( '\n Tekan 1 untuk lanjut,0 untuk berhenti:' );  
   if kont1 == 0, break; end 
      else
      fprintf('\n Nilai x0 dan x1 tidak memenuhi persyaratan');
      fprintf('\n Syarat Regula Falsi adalah fcn(x0)*fcn(x1)< 0');
      fprintf('\n input nilai x0 dan x1 kembali');
     x0 = input('\ninput tebakan x0  : ');
      x1 = input('input tebakan x1  : ');
      fprintf('\n nilai f(x0)=%10g',fcn(x0));
      fprintf('\n nilai f(x1)=%10g',fcn(x1));
      maxerror = input('\n input nilai error: ');
      maxit = input('input N max      : ');
      fplot('fcn',[-10 10]); grid on; hold on;
xlabel('SUMBU X');
ylabel('SUMBU Y');
title('VISUALISASI AKAR DENGAN METODE REGULA FALSI');
count = 0;         
rel_error = 1;     
c = x1;           
fprintf(1,'\n============================================================================'); 
fprintf('\n  No_ITerasi        X0               X1              Xr             error\n');
while (rel_error > maxerror) & (count < maxit)
  count = count + 1;
  xrold = c;
  c = x1 - fcn(x1)*(x1-x0)/(fcn(x1)-fcn(x0));
  plot(c,fcn(c),'ro');
  if c ~= 0
    rel_error = abs((c - xrold)/c) * 100;
  end
    fprintf('%3g           %10g     %10g      %10g         %10.4f\n',count,x0,x1,c,rel_error)
    test = fcn(x0) * fcn(c); 
    if test == 0
    rel_error = 0;
  elseif test < 0
    x1 = c;       
  else
    x0 = c;       
  end
end
fprintf(1,'\n============================================================================ \n'); 
fprintf(1,'                  Hasilnya (x)     :%10g   \n',c) ;
fprintf(1,'                dengan toleransi   :%10.4f \n',rel_error) ;
fprintf(1,'                  dengan iterasi   :  %3g   \n',count) ;
if rel_error>maxerror
    fprintf(1,'                                 Proses  GAGAL  \n') ;
else
    fprintf(1,'                                 Proses  SUKSES  \n') ;
end
fprintf(1,'=============================================================================');
 kont1 = input( '\n Tekan 1 untuk lanjut,0 untuk berhenti:' );  
   if kont1 == 0, break; end 
      end
end
====Semoga Bisa Membantu====

Tidak ada komentar:

Posting Komentar