diff options
author | prashantsinalkar | 2017-10-10 12:27:19 +0530 |
---|---|---|
committer | prashantsinalkar | 2017-10-10 12:27:19 +0530 |
commit | 7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch) | |
tree | dbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /260/CH3/EX3.19/3_19.sce | |
parent | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff) | |
download | Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2 Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip |
initial commit / add all books
Diffstat (limited to '260/CH3/EX3.19/3_19.sce')
-rw-r--r-- | 260/CH3/EX3.19/3_19.sce | 90 |
1 files changed, 90 insertions, 0 deletions
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<es
+ errorcheck=2;
+ end
+ end
+ iter=iter+1;
+end
+
+disp("solution Vector")
+disp(X)
+disp("iterations required for gauss siedel")
+disp(iter)
+
+iter=1;
+lambda=1.5;
+errorcheck=1;
+X=[0;0;0];
+//Gauss Siedel method with SOR
+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 errorcheck==1&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<es
+ errorcheck=2;
+ end
+ end
+ iter=iter+1;
+end
+
+disp("solution Vector")
+disp(X)
+disp("iterations required for gauss siedel with SOR")
+disp(iter)
+
+disp("these results indicate how the convergence is expedited by over-relaxation")
\ No newline at end of file |