Selasa, Maret 16, 2010

Matematika Lanjut 2

Ini adalah program perhitungan Persamaan Linier dengan metode :
1. Metode Newton Rhapson
2. Metode Gauss seide
3. Metode Jacob
4. Metode pendekatan berturut-turut
5. Metode Sekan

dibawah ini contoh codingnya dari berbagai Metode :

1. Persamaan Linier Metode NewTon Rhapson

uses crt;
const E=0.0001;
label finish;
var D,R,P:real;
x,y:array[0..20] of real;
i,Yy,j:integer;
function F(x:real):real;
begin
f:=((X*X)-25);
end;
function Ft(x:real):real;
begin
ft:=(2*X);
end;
procedure judul;
begin
textcolor(white);
writeln('================================================================');
writeln(' i | Xi | Xi+1 | F(xi) | Ft(Xi+1) | Ri |');
writeln('----------------------------------------------------------------');
end;
begin
clrscr;
clrscr;
Yy:=7;
i:=0;
j:=0;
writeln('masukkan nilai X0 = ');readln(X[i]);
writeln; judul;
repeat
begin
Y[i]:=f(X[i]);
Y[i+1]:=ft(X[i]);
D:=Abs(Y[i+1]);
if D<=E then
begin
write('akar divergen');
goto finish;
end
else
begin
X[i+1]:=X[i]-(Y[i]/Y[i+1]);
R:=Abs(X[i+1]-X[i])/X[i+1];
gotoxy(1,Yy);write('|',j);
gotoxy(9,Yy);write('|',X[i]:1:3);
gotoxy(20,Yy);write('|',X[i+1]:1:3);
gotoxy(30,Yy);write('|',Y[i]:1:3);
gotoxy(40,Yy);write('|',Y[i+1]:1:3);
gotoxy(55,Yy);write('|',R:1:3);
j:=j+1;
Yy:=Yy+1;
X[i]:=X[i+1];
end;
end;
until R<=E;
finish:
gotoxy(1,Yy+1);write('perhitungan selesai');
readln;
end.

2. Persamaan Linier Metode Gauss seidel

uses crt;
const E=0.001;
var
R:real;
x1,x2:array[0..20] of real;
i,Y,j:integer;
procedure judul;
begin
textcolor(white);
writeln('====================================================================');
writeln(' iterasi | X1 = 1.6+0.4 X2 | X2 = 1.8-0.4 X1 | R= |(xi-x(i-1)/xi |');
writeln('--------------------------------------------------------------------');
end;
begin
clrscr;
Y:=7;
i:=1;
j:=1;
write('masukkan nilai X1 = ');readln(x1[i]);
write('masukkan nilai x2 = ');readln(x2[i]);
write; judul;
repeat
begin
x1[i]:=1.6+0.4*x2[i-1];
x2[i]:=1.8-0.4*x1[i];
r:=Abs((x1[i]-x1[i-1])/x1[i]);
gotoxy(1,Y);write('|',J);
gotoxy(12,Y);write('|',x1[i]:1:3);
gotoxy(31,Y);write('|',x2[i]:1:3);
gotoxy(50,Y);write('|',R:1:3);
J:=J+1;
Y:=Y+1;
i:=i+1;
end;
until R<=E;
gotoxy(1,Y+1);write('----------------------Menggunakan metode Gauss seidel-----------------');
readln;
end.

3. Persamaan linier metode jacob

uses crt;
const E=0.001;
var
R:real;
x1,x2:array[0..20] of real;
i,Y,j:integer;
procedure judul;
begin
textcolor(white);
writeln('====================================================================');
writeln(' iterasi | X1 = 1.6+0.4 X2 | X2 = 1.8-0.4 X1 | R= |(xi-x(i-1)/xi |');
writeln('--------------------------------------------------------------------');
end;
begin
clrscr;
Y:=7;
i:=1;
j:=1;
write('masukkan nilai X1 = ');readln(x1[i]);
write('masukkan nilai x2 = ');readln(x2[i]);
write; judul;
repeat
begin
x1[i]:=1.6+0.4*x2[i-1];
x2[i]:=1.8-0.4*x1[i-1];
r:=Abs((x1[i]-x1[i-1])/x1[i]);
gotoxy(1,Y);write('|',J);
gotoxy(12,Y);write('|',x1[i]:1:3);
gotoxy(31,Y);write('|',x2[i]:1:3);
gotoxy(50,Y);write('|',R:1:3);
J:=J+1;
Y:=Y+1;
i:=i+1;
end;
until R<=E;
gotoxy(1,Y+1);write('--------------------Menggunakan metode jacob-------------------------');
readln;
end.

4. Akar dengan metode pendekatan berturut-turut

uses crt;
const E=0.001;
label back, finish;
var R,G,D,P:real;
x,y:array[0..20] of real;
i,Yy:integer;
function F(x:real):real;
begin
f:=(2*((x*x*x)+1))/7;
end;
procedure judul;
begin
textcolor(white);
writeln('==================================================');
writeln(' I | Xi | G(xi) | Abs((xi-xi-1)/xi) |');
writeln('--------------------------------------------------');
end;
begin
clrscr;
Yy:=9;
i:=1;
writeln('masukkan X0 = ');readln(x[i]);
writeln; judul;
repeat
begin
G:=f(x[i]);
D:=Abs(G);
if D>=1 then
begin
write('Divergen');
goto finish;
end
else
begin
R:=abs((G-X[i])/X[i]);
gotoxy(1,Yy);write('|',i);
gotoxy(9,Yy);write('|',X[i]:1:3);
gotoxy(20,Yy);write('|',G:1:3);
gotoxy(30,Yy);write('|',R:1:3);
i:=i+1;
Yy:=Yy+1;
X[i]:=G;
end;
end;
until R<=E;
finish:
gotoxy(1,Yy+1);write('perhitungan selesai');
readln;
end.

5. Metode sekan

uses crt;
const E= 0.001;
label back, finish;
var R,D,P:real;
x,y:array[0..20] of real;
i,Yy,j: integer;
function F(x:real):real;
begin
f:=(x*x*x)+(x*x)-(3*x)-3;
end;
procedure judul;
begin
textcolor(white);
writeln('============================================================================');
writeln(' i | Xi-1 | Xi | xi-1 | Yi-1 | Yi | Yi-1 | R |');
writeln('----------------------------------------------------------------------------');
end;
begin
clrscr;
Yy:=9;
i:=1;
j:=1;
writeln('masukkan nilai X0 = ');readln(x[i-1]);
writeln('masukkan nilai X1 = ');readln(x[i]);
writeln; judul;
repeat

begin

Y[i-1]:=f(x[i-1]);
Y[i]:=f(x[i]);
D:=Abs(Y[i]-Y[i-1]);

if D<=E then
begin
write('Iterasi Divergen');
goto finish;
end
else
begin
X[i+1]:=((X[i-1]*Y[i])-(X[i]*Y[i-1]))/(Y[i]-Y[i-1]);
y[i+1]:=f(X[i+1]);
r:=abs(f(x[i+1]));

gotoxy(1,Yy);write('|',j);
gotoxy(9,Yy);write('|',X[i-1]:1:2);
gotoxy(20,Yy);write('|',X[i]:1:2);
gotoxy(30,Yy);write('|',x[i+1]:1:2);
gotoxy(40,Yy);write('|',Y[i-1]:1:2);
gotoxy(48,Yy);write('|',y[i]:1:5);
gotoxy(56,Yy);write('|',Y[i+1]:1:5);
gotoxy(65,Yy);write('|',r:1:5);
j:=j+1;
Yy:=Yy+1;
X[i-1]:=X[i];
X[i]:=X[i+1];
Y[i-1]:=Y[i];
Y[i]:=Y[i+1];

end;

end;
until r<=E;
finish:
gotoxy(40,Yy+1);write('perhitungan selesai');
readln;
end.

Tidak ada komentar:

Copyright

Protected by Copyscape Original Content Validator
Blog ini telah dilindungi dariPenjiplakan atau Plagiarizing. Jadi jika blog/website anda mengcopy content dari blog ini silahkan cantumkan sumber dan direct linknnya. Agar terhindar dari Banned oleh Google.