summaryrefslogtreecommitdiff
path: root/191/CH2/EX2.9
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /191/CH2/EX2.9
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '191/CH2/EX2.9')
-rwxr-xr-x191/CH2/EX2.9/Example2_9.sce54
-rwxr-xr-x191/CH2/EX2.9/Result2_9.txt21
2 files changed, 75 insertions, 0 deletions
diff --git a/191/CH2/EX2.9/Example2_9.sce b/191/CH2/EX2.9/Example2_9.sce
new file mode 100755
index 000000000..a6a83da54
--- /dev/null
+++ b/191/CH2/EX2.9/Example2_9.sce
@@ -0,0 +1,54 @@
+//Solving four linear system of equations with Gauss-Seidel and SOR method
+//the convergence is much faster in SOR method
+
+clear;
+close();
+clc;
+format('v',7);
+x1=[0,0];
+x2=[0,0];
+x3=[0,0];
+x4=[0,0];
+x1(1,2)=-0.33333*(1-x2(1,1)-3*x4(1,1));
+x2(1,2)=0.16667*(1-x1(1,2)-x3(1,1));
+x3(1,2)=0.16667*(1-x2(1,2)-x4(1,1));
+x4(1,2)=-0.33333*(1-3*x1(1,2)-x3(1,2));
+i=1;
+while (abs(x1(1,1)-x1(1,2))>0.5*10^-2 | abs(x2(1,1)-x2(1,2))>0.5*10^-2 | abs(x3(1,1)-x3(1,2))>0.5*10^-2 | abs(x4(1,1)-x4(1,2))>0.5*10^-2)
+ x1(1,1)=x1(1,2);
+ x2(1,1)=x2(1,2);
+ x3(1,1)=x3(1,2);
+ x4(1,1)=x4(1,2);
+ x1(1,2)=-0.33333*(1-x2(1,1)-3*x4(1,1));
+ x2(1,2)=0.16667*(1-x1(1,2)-x3(1,1));
+ x3(1,2)=0.16667*(1-x2(1,2)-x4(1,1));
+ x4(1,2)=-0.33333*(1-3*x1(1,2)-x3(1,2));
+ i=i+1;
+end
+disp([x1; x2; x3; x4],'Answers are:')
+disp(i,'Number of Iterations :')
+
+
+w=1.6;
+x1=[0,0];
+x2=[0,0];
+x3=[0,0];
+x4=[0,0];
+x1(1,2)=x1(1,1)-0.33333*w*(1+3*x1(1,1)-x2(1,1)-3*x4(1,1));
+x2(1,2)=x2(1,1)+0.16667*w*(1-x1(1,2)-6*x2(1,2)-x3(1,1));
+x3(1,2)=x3(1,1)+0.16667*w*(1-x2(1,2)-6*x3(1,2)-x4(1,1));
+x4(1,2)=x4(1,1)-0.33333*w*(1-3*x1(1,2)-x3(1,2)+3*x4(1,1));
+i=1;
+while (abs(x1(1,1)-x1(1,2))>0.5*10^-2 | abs(x2(1,1)-x2(1,2))>0.5*10^-2 | abs(x3(1,1)-x3(1,2))>0.5*10^-2 | abs(x4(1,1)-x4(1,2))>0.5*10^-2)
+ x1(1,1)=x1(1,2);
+ x2(1,1)=x2(1,2);
+ x3(1,1)=x3(1,2);
+ x4(1,1)=x4(1,2);
+ x1(1,2)=x1(1,1)-0.33333*w*(1+3*x1(1,1)-x2(1,1)-3*x4(1,1));
+ x2(1,2)=x2(1,1)+0.16667*w*(1-x1(1,2)-6*x2(1,2)-x3(1,1));
+ x3(1,2)=x3(1,1)+0.16667*w*(1-x2(1,2)-6*x3(1,2)-x4(1,1));
+ x4(1,2)=x4(1,1)-0.33333*w*(1-3*x1(1,2)-x3(1,2)+3*x4(1,1));
+ i=i+1;
+end
+disp([x1; x2; x3; x4],'Answers are :')
+disp(i,'Number of Iterations :') \ No newline at end of file
diff --git a/191/CH2/EX2.9/Result2_9.txt b/191/CH2/EX2.9/Result2_9.txt
new file mode 100755
index 000000000..d7ac2d2ed
--- /dev/null
+++ b/191/CH2/EX2.9/Result2_9.txt
@@ -0,0 +1,21 @@
+ Answers are:
+
+ - 5.9516 - 5.9561
+ 0.9933 0.9939
+ 0.9927 0.9934
+ - 5.954 - 5.9583
+
+ Number of Iterations :
+
+ 49.
+
+Answers are :
+
+ - 6.0029 - 6.0003
+ 0.9999 1.0000
+ 1.0005 1.
+ - 6.0012 - 5.9997
+
+ Number of Iterations :
+
+ 15. \ No newline at end of file