'Masukkan Nilai NXN: ' 'Masukan Nilai Toleransi: ' 'Masukkan Harga Awal X (' ') '
This document contains code to solve a system of linear equations using Gaussian elimination. It takes user input for the matrix size and tolerance value. It initializes the matrix and constant values, performs Gaussian elimination to put the matrix in upper triangular form, and then iterates with back substitution to solve for the variables within the specified tolerance. The output displays the solved variable values and number of iterations.
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 ratings0% found this document useful (0 votes)
20 views2 pages
'Masukkan Nilai NXN: ' 'Masukan Nilai Toleransi: ' 'Masukkan Harga Awal X (' ') '
This document contains code to solve a system of linear equations using Gaussian elimination. It takes user input for the matrix size and tolerance value. It initializes the matrix and constant values, performs Gaussian elimination to put the matrix in upper triangular form, and then iterates with back substitution to solve for the variables within the specified tolerance. The output displays the solved variable values and number of iterations.
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/ 2
clear;
clc;
n=input('masukkan nilai nxn : ');
tol=input('masukan nilai toleransi: '); for i=1:n x(i)=input(['masukkan harga awal x(',num2str(i),')= ']); end a=[ 0.6 0.1765 0.1 0.112 0 0; 0.12 0.5515 0.255 0.211 0 0; 0.2 0.08 0.6 0 0 0; 0.08 0.192 0.45 0.677 0 0; 0 0 0 0 1 0.0005; 0 0 0 0 0 0.9995]; c=[1000; 3000; 1500; 900; 552.95: 100.05]; anew=zeros(n,n); cnew=zeros(n,1); for i=1:n p=2; L=1; z=1; while z~=0 if abs(a(i,p)) > abs(a(i,L)) L=p; else if p==n; z=0; else p=p+1; z=1; end end end for j=1:n anew(L,j)=a(i,j); end cnew(L,i)=c(i,1); end a=anew; c=cnew; e=1; ite=0; while max(e) > tol; ite=ite+1; for i=1:n jum=0; for j=1:n if j~=i jum=jum+a(i,j)*x(j); end end xbaru(i)=(c(i,1)-jum)/a(i,i); end for i=1:n e(i)=abs((xbaru(i)-x(i))/x(i)); x(i)=xbaru(i); end end for i=1:n disp(['nilai x(',num2str(i),') adalah ',num2str(x(i))]); end toc; disp(['ite= ',num2str(ite)]); disp(['e=',num2str(max(e))]);