summaryrefslogtreecommitdiff
path: root/3872/CH6/EX6.6/Ex6_6.sce
diff options
context:
space:
mode:
authorprashantsinalkar2017-10-10 12:27:19 +0530
committerprashantsinalkar2017-10-10 12:27:19 +0530
commit7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch)
treedbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /3872/CH6/EX6.6/Ex6_6.sce
parentb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff)
downloadScilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip
initial commit / add all books
Diffstat (limited to '3872/CH6/EX6.6/Ex6_6.sce')
-rw-r--r--3872/CH6/EX6.6/Ex6_6.sce48
1 files changed, 48 insertions, 0 deletions
diff --git a/3872/CH6/EX6.6/Ex6_6.sce b/3872/CH6/EX6.6/Ex6_6.sce
new file mode 100644
index 000000000..0347ec1a4
--- /dev/null
+++ b/3872/CH6/EX6.6/Ex6_6.sce
@@ -0,0 +1,48 @@
+//Book - Power System: Analysis & Design 5th Edition
+//Authors - J. Duncan Glover, Mulukutla S. Sarma, and Thomas J. Overbye
+//Chapter - 6 ; Example 6.6
+//Scilab Version - 6.0.0 ; OS - Windows
+
+clc;
+clear;
+
+//Solution for x^2=9 using Newton Raphson method:
+err=1;
+iternr=0; //Initial iteration value for Newton Raphson method
+tol=1e-4; //Tolerance value for Newton Raphson method
+xn=1; //Initial value for x for Newton Raphson method
+
+while err>tol
+ temp=xn;
+ J=2*xn; // Jacobian Matrix
+ xn=xn+inv(J)*(9-xn^2);
+ err=abs((xn-temp)/temp)
+ iternr=iternr+1;
+end
+
+//Solution for x^2=9 using Gauss–Seidel method
+err=1;
+D=3;
+itergs=0; //Initial iteration value for Gauss Seidal method
+xg=1; //Initial value for x for Gauss Seidal method
+
+while err>tol & itergs<iternr+1
+ temp=xg;
+ xg=xg+inv(D)*(9-xg^2)
+ err=abs((xg-temp)/temp)
+ itergs=itergs+1
+end
+printf('SOLUTION USING NEWTON RAPHSON METHOD:\n')
+printf('The convergence criterion is satisfied at the %dth iteration\n',iternr)
+printf('The solution is x=%.4f\n\n',xn)
+
+printf('SOLUTION USING GAUSS SEIDEL METHOD:\n')
+printf('The value for x at the end of %dth iteration\n',itergs)
+printf('is obtained as x=%.4f\n\n',xg)
+
+printf('COMPARISON:\n')
+if itergs>iternr
+ printf('Gauss Seidel method takes more time to converge')
+else
+ printf('Newton Raphson method takes more time to converge')
+end