From 7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 10 Oct 2017 12:27:19 +0530 Subject: initial commit / add all books --- 260/CH3/EX3.19/3_19.sce | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 260/CH3/EX3.19/3_19.sce (limited to '260/CH3/EX3.19') diff --git a/260/CH3/EX3.19/3_19.sce b/260/CH3/EX3.19/3_19.sce new file mode 100644 index 000000000..ab41a657c --- /dev/null +++ b/260/CH3/EX3.19/3_19.sce @@ -0,0 +1,90 @@ +//Eg-3.19 +//pg-123 + +clear +clc + + A=[4 2 0;0.5 1 .5;0 3 3]; + B=[2.3;1.1;14]; + + es=10^-7; + imax=100; + + X=[0;0;0]; + + iter=1; + lambda=1; + [r,c] = size(A) + n = r; + + errorcheck=1; + + //Gauss-Seidel Method + while errorcheck==1//condition for termination + for i=1:n + summ=B(i); + pivot=A(i,i); + if pivot==0 + error('gsie not applicable');//to avoid a/0 forms + end + old=X(i); + for j=1:n + if i~=j + summ=summ-A(i,j)*X(j); + end + end + X(i)=(lambda*summ/pivot)+(1-lambda)*old;//relaxation + if X(i)~=0 then + AbsErr=abs((X(i)-old)/X(i))*100;//absolute error + else + output=('error cannot be computed')//since xi cant be equal to zero + end + if AbsErr