Source code :
clc;
clear all;
disp('===============================================');
disp('===== Nama : Desianny Amalia Fauziah =======');
disp('===== NIM : 5302413057 =======');
disp('===== Prodi : PTIK =======');
disp('===== Rombel : 2 =======');
disp('===============================================');
disp('== Pencarian akar dengan Iterasi Gauss Seidel =');
disp('== 1. 12a + 3 b - 5 c = 1 ==');
disp('== 2. 1 a + 5 b + 3 c = 28 ==');
disp('== 3. 3 a + 7 b + 13c = 76 ==');
disp('===============================================');
A = [12,3,-5; 1,5,3; 3,7,13];
C = [1;28;76];
n = length(C);
X = zeros(n,1);
error = ones(n,1);
% UNTUK MENGECEK DIAGONAL DOMINAN
for i = 1:n
j = 1:n;
j(i) = [];
B = abs(A(i,j));
Check(i) = abs(A(i,i)) - sum(B);
if Check(i) < 0
fprintf('Matriks tidak dominan pada baris ke %2i\n\n',i)
end
end
% MULAI ITERASI DARI 0
iteration = 0;
while max(error) > 0.0001
iteration = iteration + 1;
Z = X;
for i = 1:n
j = 1:n;
j(i) = [];
Xtemp = X;
Xtemp(i) = [];
X(i) = (C(i) - sum(A(i,j) * Xtemp)) / A(i,i);
end
Xsolution(:,iteration) = X;
error = sqrt((X - Z).^2);
end
% HASIL
Matrix = [A C]
disp('Iterasi A B C');
Iterasi_X = [1:iteration;Xsolution]'
disp(sprintf('X ditemukan iterasi ke-%1g',iteration));
disp('');
disp('Nilai Akar Hasil Perhitungan');
Matriks_x = [X]
Pascal / c++ / c# mba ee
BalasHapusscilab / matlab mas
BalasHapus