0

Source Code Pascal Metode Regula Falsi dan Metode Bagi-dua

Posted by Jujur Sitanggang on 10:50 AM


  • Tugas Metode Numerik !

  • Buat Program pascal dari fungsi F(x)=e^x-5x^2 Selangnya [0,1] dan epsiloonnya=0.00001
    dengan menu pilihan yaitu metode bagi - dua dan metode regula falsi


  • Source Code Pascal Metode Regula Falsi dan Metode Bagi-dua

program metode_numerik;

uses crt;

var
  pil:integer;
  ulang:char;

procedure metode_bagi_dua;

var
  a,b,x,Fa,Fb,tol,fx: real;
  i,n : integer;
  e, error : real;

begin
    writeln('==============================================================');
    writeln('                       METODE BAGI-DUA                        ');
    writeln('==============================================================');
    a:=0;
    b:=1;
    e:=0.00001;
    n:=13;
    readln;
    i:=0;
    fa:=exp(a)-5*sqr(a);
    fb:=exp(b)-5*sqr(b);
    writeln('');
    if (fa * fb > 0) then writeln('Nilai F(a) * f(b) > 0')
    else
        writeln('--------------------------------------------------------------');
        writeln('Iterasi   a       b        x         f(a)       f(x)  error');
        writeln('--------------------------------------------------------------');
        tol:=e+1;
        while (i<=n) and (tol>e) do
        begin
             i:=i+1;
             x:=(a+b)/2;
             fx:=exp(x)-5*sqr(x);
             error:=abs((x-a)/x); {metode bagi dua}
             write(i:6,'',a:8:4,'',b:8:4,'',x:10:5);
             writeln(fa:10:5,'',fx:10:5,'',error:8);
             e:=abs(x-a);
             if(fa*fx <=0) then
             begin
                   b:=x;
                   fb:=fx;
                   end
                   else
                   begin
                        a:=x;
                        fa:=fx;
                   end;
             end;
             writeln('--------------------------------------------------------------');
             if (i<=n) then
             begin
                  writeln('Pendekatan akar dari f(x) = e^x-5X^2 adalah = ',x:3:7);
                  writeln('Toleransi Terpenuhi');
                  end
                  else
                      writeln('Pendekatan akar dari f(x) = e^x-5X^2 adalah = ',x:3:7);
                      writeln('Toleransi Tidak Terpenuhi');
                      readln;
                  end;

procedure metode_regula_falsi;

var
  a,b,x,Fa,Fb,tol,fx,c : real;
  i,n                  : integer;
  e,error              : real;

begin
    writeln('==============================================================');
    writeln('                     METODE REGULA FALSI                      ');
    writeln('==============================================================');
    a:=0;
    b:=1;
    e:=0.00001;
    n:=13;
    readln;
    i:=0;
    fa:=exp(a)-5*sqr(a);
    fb:=exp(b)-5*sqr(b);
    writeln('');
    if (fa * fb > 0) then writeln('Nilai F(a) * f(b) > 0')
    else
        writeln('--------------------------------------------------------------');
        writeln('Iterasi   a       b        x         f(a)       f(x)  error');
        writeln('--------------------------------------------------------------');
        tol:=e+1;
        while (i<=n) and (tol>e) do
        begin
             i:=i+1;
             x:=a-fa*(b-a)/(fb-fa); {metode regula falsi}
             fx:=exp(x)-5*sqr(x);
             error:=abs((x-a)/x);
             write(i:6,'',a:8:4,'',b:8:4,'',x:10:5);
             writeln(fa:10:5,'',fx:10:5,'',error:8);
             e:=abs(x-a);
             if(fa*fx <=0) then
             begin
                  b:=x;
                  fb:=fx;
                  end
                  else
                  begin
                       a:=x;
                       fa:=fx;
                  end;
             end;
             writeln('--------------------------------------------------------------');
             if (i<=n) then
             begin
                  writeln('Pendekatan akar dari f(x) = e^x-5X^2 adalah = ',x:3:7);
                  writeln('Toleransi Terpenuhi');
                  end
                  else
                      writeln('Pendekatan akar dari f(x) = e^x-5X^2 adalah = ',x:3:7);
                      writeln('Toleransi Tidak Terpenuhi');
                      readln;
             end;

begin
    repeat
    clrscr;
    writeln('          Menu Metode Numerik         ');
    writeln('--------------------------------------');
    writeln('1. METODE BAGI-DUA');
    writeln('2. METODE REGULA FALSI');
    writeln('3. Exit');
    writeln('--------------------------------------');
    write('Pilih Menu = '); read(pil);
    clrscr;

    case pil of
         1 : metode_bagi_dua;
         2 : metode_regula_falsi;
         3 : exit;
    end;
    if (pil > 3) then
    begin
         writeln('pilihan yang anda masukan salah = ');
         readln;
         write('');
    end;
    until (ulang='Y')  or (ulang='y');
end.






























  • PrintScreen Program dalam Bahasa Pascal


















  • Hasil Running Program



  1. Metode Bagi-Dua


  1. Metode Regula-Falsi


0 Comments

Copyright Jujur Soaloon Sitangang Lipan All rights reserved. Theme by Sitanggang. | Bloggerized by Soalparna.