Selasa, 03 Juni 2014

Metode AdamsBashforthMoulton






 

























Algoritma program Pascal untuk menyelesaikan masalah nilai awal pada persamaan diferensial biasa orde satu menggunakan Metode Adams-Bashforth-Moulton.
program AdamsBashforthMoulton;
uses wincrt;
var
   n                                         : integer;
   vinterval1, vinterval2, h, k1, k2, k3, k4 : real;
   x, y, yaksen, yABM, yaksenABM             : array [0..100] of real;

function fungsi(x,y:real):real;
begin
     fungsi:= y-x;
end;

label 1, 2, 3, 4, 5;

begin
{Input diketahui}
writeln('Program Adam Bashforth Moulton.');
writeln('Diketahui : y` = y - x');
writeln('            Pada interval [a,b]');
write('              a = ');read(vinterval1);x[0]:= vinterval1;
write('              b = ');readln(vinterval2);
write('             y(',vinterval1:0:0,') = ');readln(y[0]);
write('             n = ');readln(n);h:= (vinterval2-vinterval1)/n;

{Pencarian 3 nilai awal Runge-Kutta}
n:= 0;
1:
x[n+1]:= x[n] + h;
if x[n+1] < vinterval2 then
begin
     n:= n+1;
     goto 1;
end;

     for n:= 0 to 2 do
     begin
          k1:= h*fungsi(x[n],y[n]);
          k2:= h*fungsi((x[n]+(1/2)*h),(y[n]+(1/2)*k1));
          k3:= h*fungsi((x[n]+(1/2)*h),(y[n]+(1/2)*k2));
          k4:= h*fungsi((x[n]+h),(y[n]+k3));
          y[n+1]:= y[n] + (1/6)*(k1+2*k2+2*k3+k4);
     end;

{Penghitungan nilai y aksen awal}
begin
     for n:= 0 to 3 do
     begin
          yaksen[n]:= fungsi(x[n],y[n]);
     end;
end;

{Penghitungan nilai ABM, catatan n=3}
n:= 3;
begin
2:
     yABM[n+1]:= y[n] + (h/24) * (55*yaksen[n] - 59*yaksen[n-1] + 37*yaksen[n-2] - 9*yaksen[n-3]);
     yaksenABM[n+1]:= fungsi(x[n+1],yABM[n+1]);
     y[n+1]:= y[n] + (h/24) * (9*yaksenABM[n+1] + 19*yaksen[n] - 5*yaksen[n-1] + yaksen[n-2]);
     yaksen[n+1]:= fungsi(x[n+1],y[n+1]);

     if x[n+1] > vinterval2 then goto 3;
    
n:= n+1;goto 2;
end;

3:
{Pencetakan hasil ABM}
n:= 0;
begin
     writeln;
     writeln('| x[n] |    py[n]    |     y[n]    |');
4:

          if n <= 3 then
          begin
               writeln('| ',x[n]:0:2,' |      -      |  ',y[n]:0:7,'  |');
          end;

          if n > 3 then
          begin
               writeln('| ',x[n]:0:2,' |  ',yABM[n]:0:7,'  |  ',y[n]:0:7,'  |');
          end;

if x[n] < vinterval2 then
begin
n:= n+1;goto 4;
end;

if x[n] > vinterval2 then goto 5;
end;

5:
end.


Preview program:

Tidak ada komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...