diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /191/CH3/EX3.5/Example3_5.sce | |
download | Scilab-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/CH3/EX3.5/Example3_5.sce')
-rwxr-xr-x | 191/CH3/EX3.5/Example3_5.sce | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/191/CH3/EX3.5/Example3_5.sce b/191/CH3/EX3.5/Example3_5.sce new file mode 100755 index 000000000..782e72a77 --- /dev/null +++ b/191/CH3/EX3.5/Example3_5.sce @@ -0,0 +1,37 @@ +//Newton's Method
+//the first few iteration converges quikcly in negative root as compared to positive root
+clc;
+clear;
+close();
+funcprot(0);
+format('v',9);
+deff('[Newton]=fx(x)','Newton=exp(x)-x-2');
+deff('[diff]=gx(x)','diff=exp(x)-1');
+x = linspace(-2.5,1.5);
+plot(x,exp(x)-x-2)
+//from the graph the function has 2 roots
+//considering the initial negative root -10
+x1 = -10;
+x2 = x1-fx(x1)/gx(x1);
+i=0;
+while abs(x1-x2)>(0.5*10^-7)
+ x1=x2;
+ x2 = x1-fx(x1)/gx(x1);
+ i=i+1;
+end
+disp(i,'Number of iterations : ')
+disp(x2,'The negative root of the function is : ')
+
+
+//considering the initial positive root 10
+x1 = 10;
+x2 = x1-fx(x1)/gx(x1);
+i=0;
+while abs(x1-x2)>(0.5*10^-7)
+ x1=x2;
+ x2 = x1-fx(x1)/gx(x1);
+ i=i+1;
+end
+disp(i,'Number of iteration : ')
+disp(x2,'The positive root of the function is : ')
+//number of iterations showing fast and slow convergent
\ No newline at end of file |