0% found this document useful (0 votes)
39 views4 pages

All 'Masukkan Nilai Matrix NXN ' 'Masukkan Nilai Matrix nx1 '

The document describes an iterative method to solve a system of linear equations. It inputs matrix A and vector B, initializes vector x, and iterates to minimize the error between x and the solution. Each iteration updates x based on the other terms. After 31 iterations, it outputs the final values of x, with errors less than 0.001.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

All 'Masukkan Nilai Matrix NXN ' 'Masukkan Nilai Matrix nx1 '

The document describes an iterative method to solve a system of linear equations. It inputs matrix A and vector B, initializes vector x, and iterates to minimize the error between x and the solution. Each iteration updates x based on the other terms. After 31 iterations, it outputs the final values of x, with errors less than 0.001.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

clc

clear all
A = input ('Masukkan Nilai Matrix nxn ');
B = input ('Masukkan Nilai Matrix nx1 ');
n = length (B); %dimensi terbesar dimatrix
x = zeros (n,1);
error = ones (n,1);

% =iterasi
it=0;
iterasi=0;
while max(error) >0.00001
it=it+1;
iterasi=iterasi+1;
e=x
for i=1:n
j=1:n;
j(i)=[];% j=i tidak dianggap untuk
perhitungan selanjutnya
xtemp=x; %nilai x sementara
xtemp(i)=[];
x(i)=(B(i)-sum(A(i,j)*xtemp))/A(i,i);
end
xsolution(:,it)=x
error=sqrt((x-e).^2)';
end

%menampilkan hasil
NumIteration=transpose([1:it]);
x1=transpose(xsolution(1,:));
x2=transpose(xsolution(2,:));
x3=transpose(xsolution(3,:));
iterasi
T=table (NumIteration,x1,x2,x3);
Masukkan Nilai Matrix nxn [3 4.3333 3.9667 4.0033 5.0000
0 1; 2 -3 0; 1 3 -10]
5.2222 4.9778 5.0022 1.0000
Masukkan Nilai Matrix nx1
1.1000 0.9900 1.0010 xsolution =
[13;-7;9]
e= 4.3333 3.9667 4.0033
e=
3.9997 4.0000 4.0000
4.0033
0
5.2222 4.9778 5.0022
5.0022
0 4.9998 5.0000 5.0000
1.0010
0 1.1000 0.9900 1.0010
xsolution = 0.9999 1.0000 1.0000
xsolution =
4.3333 3.9667 4.0033 e=
4.3333
3.9997
4.0000
5.2222
5.2222 4.9778 5.0022
5.0000
1.1000 4.9998
1.0000
e= 1.1000 0.9900 1.0010
0.9999
4.3333
e= xsolution =
5.2222
3.9997 4.3333 3.9667 4.0033
1.1000
3.9997 4.0000 4.0000
4.9998
xsolution = 4.0000
0.9999
4.3333 3.9667 5.2222 4.9778 5.0022
xsolution = 4.9998 5.0000 5.0000
5.2222 4.9778 5.0000
4.3333 3.9667 4.0033
1.1000 0.9900 1.1000 0.9900 1.0010
3.9997 4.0000
e= 0.9999 1.0000 1.0000
5.2222 4.9778 5.0022 1.0000
3.9667 4.9998 5.0000
iterasi =
4.9778 1.1000 0.9900 1.0010
0.9999 1.0000 7
0.9900
e=
xsolution =
4.0000
Nomor 2

clc
clear all
A = input ('Masukkan Nilai Matrix nxn ');
B = input ('Masukkan Nilai Matrix nx1 ');
n = length (B); %dimensi terbesar dimatrix
x = zeros (n,1);
error = ones (n,1);

% =iterasi
it=0;
iterasi=0;
while max(error) >0.001
it=it+1;
iterasi=iterasi+1;
e=x
for i=1:n
j=1:n;
j(i)=[];% j=i tidak dianggap untuk
perhitungan selanjutnya
xtemp=x; %nilai x sementara
xtemp(i)=[];
x(i)=(B(i)-sum(A(i,j)*xtemp))/A(i,i);
end
xsolution(:,it)=x
error=sqrt((x-e).^2)';
end

%menampilkan hasil
NumIteration=transpose([1:it]);
x1=transpose(xsolution(1,:));
x2=transpose(xsolution(2,:));
x3=transpose(xsolution(3,:));
x4=transpose(xsolution(3,:));
x5=transpose(xsolution(3,:));
iterasi
T=table (NumIteration,x1,x2,x3,x4,x5);
xsolution =

Columns 1 through 11

0 0 0.2604 0.0651 0.2116 0.1017 0.1841 0.1223 0.1687 0.1339 0.1600

0 -0.1563 -0.0391 -0.1270 -0.0610 -0.1105 -0.0734 -0.1012 -0.0803 -0.0960 -0.0843

0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250

-0.3750 -0.4688 -0.3984 -0.4512 -0.4116 -0.4413 -0.4190 -0.4357 -0.4232 -0.4326 -0.4256

0 0.1250 0.0313 0.1016 0.0488 0.0884 0.0587 0.0810 0.0643 0.0768 0.0674

Columns 12 through 22

0.1404 0.1551 0.1441 0.1523 0.1462 0.1508 0.1473 0.1499 0.1480 0.1494 0.1483

-0.0931 -0.0865 -0.0914 -0.0877 -0.0905 -0.0884 -0.0900 -0.0888 -0.0897 -0.0890 -0.0895

0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250

-0.4308 -0.4269 -0.4298 -0.4276 -0.4293 -0.4280 -0.4290 -0.4283 -0.4288 -0.4284 -0.4287

0.0744 0.0692 0.0731 0.0702 0.0724 0.0707 0.0720 0.0710 0.0717 0.0712 0.0716

Column 23 through 31

0.1492 0.1485 0.1490 0.1487 0.1489 0.1487 0.1489 0.1488 0.1488

-0.0891 -0.0894 -0.0892 -0.0894 -0.0892 -0.0893 -0.0893 -0.0893 -0.0893

0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250 0.6250

-0.4285 -0.4286 -0.4285 -0.4286 -0.4285 -0.4286 -0.4286 -0.4286 -0.4286

0.0713 0.0715 0.0714 0.0715 0.0714 0.0715 0.0714 0.0714 0.0714

Diperlukan lebih dari 31 iterasi untuk mendapatkan hasil terbaik (error yang saya pilih < 0.001).
Berdasarkan iterasi terakhir diperoleh besar P1= 0.1488 ; P2=-0,0893 ; P3=0.6250 ; P4=-0.4286 ; P5 =
0.0714.

You might also like