diff options
Diffstat (limited to '191/CH3')
-rwxr-xr-x | 191/CH3/EX3.1/Example3_1.sce | 35 | ||||
-rwxr-xr-x | 191/CH3/EX3.1/Figure3_1.png | bin | 0 -> 4048 bytes | |||
-rwxr-xr-x | 191/CH3/EX3.1/Result3_1.txt | 28 | ||||
-rwxr-xr-x | 191/CH3/EX3.2/Example3_2.sce | 35 | ||||
-rwxr-xr-x | 191/CH3/EX3.2/Figure3_2.png | bin | 0 -> 4365 bytes | |||
-rwxr-xr-x | 191/CH3/EX3.2/Result3_2.txt | 14 | ||||
-rwxr-xr-x | 191/CH3/EX3.3/Example3_3.sce | 40 | ||||
-rwxr-xr-x | 191/CH3/EX3.3/Result3_3.txt | 10 | ||||
-rwxr-xr-x | 191/CH3/EX3.4/Example3_4.sce | 40 | ||||
-rwxr-xr-x | 191/CH3/EX3.4/Figure3_4.png | bin | 0 -> 4362 bytes | |||
-rwxr-xr-x | 191/CH3/EX3.4/Result3_4.txt | 2 | ||||
-rwxr-xr-x | 191/CH3/EX3.5/Example3_5.sce | 37 | ||||
-rwxr-xr-x | 191/CH3/EX3.5/Figure3_5.png | bin | 0 -> 5052 bytes | |||
-rwxr-xr-x | 191/CH3/EX3.5/Result3_5.txt | 17 | ||||
-rwxr-xr-x | 191/CH3/EX3.6/Example3_6.sce | 51 | ||||
-rwxr-xr-x | 191/CH3/EX3.6/Figure3_6.png | bin | 0 -> 4052 bytes | |||
-rwxr-xr-x | 191/CH3/EX3.6/Result3_6.txt | 20 | ||||
-rwxr-xr-x | 191/CH3/EX3.7/Example3_7.sce | 32 | ||||
-rwxr-xr-x | 191/CH3/EX3.7/Result3_7.txt | 9 | ||||
-rwxr-xr-x | 191/CH3/EX3.8/Example3_8.sce | 34 | ||||
-rwxr-xr-x | 191/CH3/EX3.8/Result3_8.txt | 10 |
21 files changed, 414 insertions, 0 deletions
diff --git a/191/CH3/EX3.1/Example3_1.sce b/191/CH3/EX3.1/Example3_1.sce new file mode 100755 index 000000000..5a09ca883 --- /dev/null +++ b/191/CH3/EX3.1/Example3_1.sce @@ -0,0 +1,35 @@ +//Bisection Method
+clc;
+clear;
+close();
+format('v',9);
+b(1)=1;a(1)=0;k=5;
+deff('[fx]=bisec(x)','fx =(x+1).^2.*exp(x.^2-2)-1');
+x = linspace(0,1);
+plot(x,((x+1).^2).*(exp(x.^2-2))-1);
+//in interval [0,1]changes its sign thus has a root
+//k = no of decimal place of accuracy
+//a = lower limit of interval
+//b = upper limit of interval
+//n = no of iterations required
+n = log2((10^k)*(b-a));
+n = ceil(n);
+disp(n,'Number of iterations : ')
+for i = 1:n-1
+ N(i) = i;
+ c(i) = (a(i)+b(i))/2;
+ bs(i) = bisec(c(i));
+ if (bisec(b(i))*bisec(c(i))<0)
+ a(i+1)=c(i);
+ b(i+1)=b(i);
+ else
+ b(i+1)=c(i);
+ a(i+1)=a(i);
+ end
+end
+N(i+1)=i+1;
+c(i+1) = (a(i+1)+b(i+1))/2;
+bs(i+1) = bisec(c(i));
+ann = [N a b c bs];
+disp(ann , 'The Table : ');
+disp(c(i),'The root of the function is : ')
\ No newline at end of file diff --git a/191/CH3/EX3.1/Figure3_1.png b/191/CH3/EX3.1/Figure3_1.png Binary files differnew file mode 100755 index 000000000..55872eef9 --- /dev/null +++ b/191/CH3/EX3.1/Figure3_1.png diff --git a/191/CH3/EX3.1/Result3_1.txt b/191/CH3/EX3.1/Result3_1.txt new file mode 100755 index 000000000..c78d978b7 --- /dev/null +++ b/191/CH3/EX3.1/Result3_1.txt @@ -0,0 +1,28 @@ +
+ Number of iterations :
+
+ 17.
+
+ The Table :
+
+ 1. 0. 1. 0.5 - 0.609009
+ 2. 0.5 1. 0.75 - 0.272592
+ 3. 0.75 1. 0.875 0.023105
+ 4. 0.75 0.875 0.8125 - 0.139662
+ 5. 0.8125 0.875 0.84375 - 0.062448
+ 6. 0.84375 0.875 0.859375 - 0.020775
+ 7. 0.859375 0.875 0.867188 0.000881
+ 8. 0.859375 0.867188 0.863281 - 0.010017
+ 9. 0.863281 0.867188 0.865234 - 0.004585
+ 10. 0.865234 0.867188 0.866211 - 0.001857
+ 11. 0.866211 0.867188 0.866699 - 0.000489
+ 12. 0.866699 0.867188 0.866943 0.000196
+ 13. 0.866699 0.866943 0.866821 - 0.000147
+ 14. 0.866821 0.866943 0.866882 0.000025
+ 15. 0.866821 0.866882 0.866852 - 0.000061
+ 16. 0.866852 0.866882 0.866867 - 0.000018
+ 17. 0.866867 0.866882 0.866875 - 0.000018
+
+ The root of the function is :
+
+ 0.866867
\ No newline at end of file diff --git a/191/CH3/EX3.2/Example3_2.sce b/191/CH3/EX3.2/Example3_2.sce new file mode 100755 index 000000000..706f6bb6f --- /dev/null +++ b/191/CH3/EX3.2/Example3_2.sce @@ -0,0 +1,35 @@ +//The solution using false position method
+clc;
+clear;
+close();
+b(1)=1;a(1)=0;k=5;i=1;
+format('v',9);
+deff('[fx]=bisec(x)','fx =(x+1)^2*exp(x^2-2)-1');
+x = linspace(0,1);
+plot(x,((x+1).^2).*(exp(x.^2-2))-1);
+//in interval [0,1]changes its sign thus has a root
+//k = no of decimal place of accuracy
+//a = lower limit of interval
+//b = upper limit of interval
+c(i) = (a(i)*bisec(b(i))-b(i)*bisec(a(i)))/(bisec(b(i))-bisec(a(i)));
+bs(1)=bisec(c(1));
+N(1) = 1;
+a(i+1)=c(i);
+b(i+1)=b(i);
+while abs(bisec(c(i)))>(0.5*(10^-k))
+ i = i+1;
+ N(i)=i;
+ c(i) = (a(i)*bisec(b(i))-b(i)*bisec(a(i)))/(bisec(b(i))-bisec(a(i)));
+ bs(i) = bisec(c(i));
+ if (bisec(b(i))*bisec(c(i))<0)
+ a(i+1)=c(i);
+ b(i+1)=b(i);
+ else
+ b(i+1)=c(i);
+ a(i+1)=a(i);
+ end
+end
+a(10)=[];b(10)=[];
+ann = [N a b c bs];
+disp(ann , 'The Table : ');
+disp('The root of the function is bracketed by [0.647116 1] ');
\ No newline at end of file diff --git a/191/CH3/EX3.2/Figure3_2.png b/191/CH3/EX3.2/Figure3_2.png Binary files differnew file mode 100755 index 000000000..9303d1a44 --- /dev/null +++ b/191/CH3/EX3.2/Figure3_2.png diff --git a/191/CH3/EX3.2/Result3_2.txt b/191/CH3/EX3.2/Result3_2.txt new file mode 100755 index 000000000..847340152 --- /dev/null +++ b/191/CH3/EX3.2/Result3_2.txt @@ -0,0 +1,14 @@ +
+ The Table :
+
+ 1. 0. 1. 0.647116 - 0.441885
+ 2. 0.647116 1. 0.817834 - 0.127033
+ 3. 0.817834 1. 0.856496 - 0.028617
+ 4. 0.856496 1. 0.864707 - 0.006057
+ 5. 0.864707 1. 0.866422 - 0.001265
+ 6. 0.866422 1. 0.866780 - 0.000263
+ 7. 0.866780 1. 0.866854 - 0.000055
+ 8. 0.866854 1. 0.866869 - 0.000011
+ 9. 0.866869 1. 0.866873 - 0.000002
+
+ The root of the function is bracketed by [0.647116 1]
\ No newline at end of file diff --git a/191/CH3/EX3.3/Example3_3.sce b/191/CH3/EX3.3/Example3_3.sce new file mode 100755 index 000000000..0cd02ef26 --- /dev/null +++ b/191/CH3/EX3.3/Example3_3.sce @@ -0,0 +1,40 @@ +//We have quadratic equation x^2-2*x-8=0 with roots -2 and 4
+//for solving it we use fixed point iteration method for that we rearrange it in 3 ways.
+//first way x=(2*x+8)^(1/2)
+//here x0 is chosen arbitrarily
+
+clear;
+clc;
+close();
+format('v',5)
+funcprot(0);
+deff('[fixed_point]=fx(x)','fixed_point=(2*x+8)^0.5')
+x0=5;
+while abs(x0-fx(x0))>0.5*10^(-2)
+ x0=fx(x0);
+end
+disp(x0,'root is :')
+
+//second way x=(2*x+8)/x
+
+format('v',5)
+funcprot(0);
+deff('[fixed_point]=fx(x)','fixed_point=(2*x+8)/x')
+x0=5;
+while abs(x0-fx(x0))>0.5*10^(-2)
+ x0=fx(x0);
+end
+disp(x0,'root is :')
+
+//third way x=(x^2-8)/2
+
+format('v',10)
+funcprot(0);
+deff('[fixed_point]=fx(x)','fixed_point=(x^2-8)/2')
+x0=5;
+for i=1:5
+ x0=fx(x0);
+ disp(x0,'value is :')
+end
+disp(x0,'As you can see that the root is not converging.So this method is not applicable.')
+
diff --git a/191/CH3/EX3.3/Result3_3.txt b/191/CH3/EX3.3/Result3_3.txt new file mode 100755 index 000000000..09b6b4261 --- /dev/null +++ b/191/CH3/EX3.3/Result3_3.txt @@ -0,0 +1,10 @@ +(i)
+ root is :
+
+ 4.
+(ii)
+ root is :
+
+ 4.
+(iii)
+root is not converging.So this method is not applicable.
\ No newline at end of file diff --git a/191/CH3/EX3.4/Example3_4.sce b/191/CH3/EX3.4/Example3_4.sce new file mode 100755 index 000000000..0dc785a70 --- /dev/null +++ b/191/CH3/EX3.4/Example3_4.sce @@ -0,0 +1,40 @@ +//checking for the convergence and divergence of different functions we are getting after rearrangement of the given quadratic equation x^2-2*x-8=0.
+//after first type of arrangement we get a function gx=(2*x+8)^(1/2).for this we have..
+
+clear;
+clc;
+close();
+alpha=4;
+I=alpha-1:alpha+1;//required interval
+deff('[f1]=gx(x)','f1=(2*x+8)^(1/2)');
+deff('[f2]=diffgx(x)','f2=(2*x+8)^(-0.5)');
+x=linspace(3,5);
+subplot(2,1,1);
+plot(x,(2*x+8)^(1/2))
+plot(x,x)
+x0=5;
+if diffgx(I)>0
+ disp('Errors in two consecutive iterates are of same sign so convergence is monotonic')
+end
+if abs(diffgx(x0))<1
+ disp('So this method converges')
+end
+
+//after second type of arrangement we get a function gx=(2*x+8)/x.for this we have..
+
+deff('[f1]=gx(x)','f1=(2*x+8)/x');
+deff('[f2]=diffgx(x)','f2=(-8)/(x^2)');
+x=linspace(1,5);
+for i=1:100
+ y(1,i)=2+8/x(1,i);
+end
+subplot(2,1,2);
+plot(x,y)
+plot(x,x)
+x0=5;
+if diffgx(I)<0
+ disp('Errors in two consecutive iterates are of opposite sign so convergence is oscillatory')
+end
+if abs(diffgx(x0))<1
+ disp('So this method converges')
+end
diff --git a/191/CH3/EX3.4/Figure3_4.png b/191/CH3/EX3.4/Figure3_4.png Binary files differnew file mode 100755 index 000000000..9d261d93e --- /dev/null +++ b/191/CH3/EX3.4/Figure3_4.png diff --git a/191/CH3/EX3.4/Result3_4.txt b/191/CH3/EX3.4/Result3_4.txt new file mode 100755 index 000000000..7964935a7 --- /dev/null +++ b/191/CH3/EX3.4/Result3_4.txt @@ -0,0 +1,2 @@ +(i) Errors in two consecutive iterates are of same sign so convergence is monotonic
+(ii) Errors in two consecutive iterates are of opposite sign so convergence is oscillatory.
\ No newline at end of file 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 diff --git a/191/CH3/EX3.5/Figure3_5.png b/191/CH3/EX3.5/Figure3_5.png Binary files differnew file mode 100755 index 000000000..a14280044 --- /dev/null +++ b/191/CH3/EX3.5/Figure3_5.png diff --git a/191/CH3/EX3.5/Result3_5.txt b/191/CH3/EX3.5/Result3_5.txt new file mode 100755 index 000000000..189069cc1 --- /dev/null +++ b/191/CH3/EX3.5/Result3_5.txt @@ -0,0 +1,17 @@ +
+ Number of iterations :
+
+ 4.
+
+ The negative root of the function is :
+
+ - 1.841406
+
+ Number of iteration :
+
+ 13.
+
+ The positive root of the function is :
+
+ 1.146193
+
\ No newline at end of file diff --git a/191/CH3/EX3.6/Example3_6.sce b/191/CH3/EX3.6/Example3_6.sce new file mode 100755 index 000000000..3ac4c3f2d --- /dev/null +++ b/191/CH3/EX3.6/Example3_6.sce @@ -0,0 +1,51 @@ +//Secant Method
+//the first few iteration converges quikcly in negative root as compared to positive root
+clc;
+clear;
+close();
+funcprot(0);
+format('v',9);
+deff('[Secant]=f(x)','Secant=exp(x)-x-2');
+x = linspace(0,1.5);
+subplot(2,1,1);
+plot(x,exp(x)-x-2);
+plot(x,0);
+//from the graph the function has 2 roots
+//considering the initial negative root -10
+x0 = -10
+x1 = -9;
+x2 = (x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
+i=0;
+while abs(x1-x2)>(0.5*10^-7)
+ x0=x1;
+ x1=x2;
+ x2 = (x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
+ i=i+1;
+end
+disp(i,'Number of iterations : ')
+disp(x2,'The negative root of the function is : ')
+
+
+//considering the initial positive root 10
+subplot(2,1,2);
+x = linspace(-2.5,0);
+plot(x,exp(x)-x-2);
+plot(x,0);
+x0 = 10
+x1 = 9;
+x2 = (x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
+i=0;
+while abs(x1-x2)>(0.5*10^-7)
+ x0=x1;
+ x1=x2;
+ x2 = (x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
+ 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
+
+format('v',6)
+//Order of secant method (p)
+ p = log(31.52439)/log(8.54952);
+ disp(p,'Order of Secant Method : ')
\ No newline at end of file diff --git a/191/CH3/EX3.6/Figure3_6.png b/191/CH3/EX3.6/Figure3_6.png Binary files differnew file mode 100755 index 000000000..d9b1f5e69 --- /dev/null +++ b/191/CH3/EX3.6/Figure3_6.png diff --git a/191/CH3/EX3.6/Result3_6.txt b/191/CH3/EX3.6/Result3_6.txt new file mode 100755 index 000000000..b017e4d29 --- /dev/null +++ b/191/CH3/EX3.6/Result3_6.txt @@ -0,0 +1,20 @@ +
+ Number of iterations :
+
+ 5.
+
+ The negative root of the function is :
+
+ - 1.841406
+
+ Number of iteration :
+
+ 18.
+
+ The positive root of the function is :
+
+ 1.146193
+
+ Order of Secant Method :
+
+ 1.608
\ No newline at end of file diff --git a/191/CH3/EX3.7/Example3_7.sce b/191/CH3/EX3.7/Example3_7.sce new file mode 100755 index 000000000..153500b6c --- /dev/null +++ b/191/CH3/EX3.7/Example3_7.sce @@ -0,0 +1,32 @@ +//Non-Linear Equation
+clc;
+clear;
+close();
+funcprot(0);
+format('v',9);
+i = 1;
+deff('[func1]=f(x,y)','func1=x^2+y^2-4');
+deff('[func2]=g(x,y)','func2=2*x-y^2');
+deff('[difffx]=fx(x)','difffx=2*x');
+deff('[difffy]=fy(y)','difffy=2*y');
+deff('[diffgx]=gx(x)','diffgx=2');
+deff('[diffgy]=gy(y)','diffgy=-2*y');
+x1(i)=1;y1(i)=1;
+J = [fx(x1(i)),fy(y1(i));gx(x1(i)),gy(y1(i))];
+n=[x1(i);y1(i)]-inv(J)*[f(x1(i),y1(i));g(x1(i),y1(i))];
+x2(i)=n(1,1);y2(i)=n(2,1);
+N(1)=i-1;
+while (abs(x2(i)-x1(i))>0.5*10^-7) | (abs(y2(i)-y1(i))>0.5*10^-7)
+ i=i+1;
+ N(i)=i-1;
+ x1(i)=x2(i-1);
+ y1(i)=y2(i-1);
+ J = [fx(x1(i)),fy(y1(i));gx(x1(i)),gy(y1(i))];
+ n=[x1(i);y1(i)]-inv(J)*[f(x1(i),y1(i));g(x1(i),y1(i))];
+ x2(i)=n(1,1);y2(i)=n(2,1);
+end
+N(i+1)=i;
+x1(i+1) = x2(i);
+y1(i+1) = y2(i);
+n = [N x1 y1];
+disp(n,'The value of n x and y :')
\ No newline at end of file diff --git a/191/CH3/EX3.7/Result3_7.txt b/191/CH3/EX3.7/Result3_7.txt new file mode 100755 index 000000000..9d256e2bd --- /dev/null +++ b/191/CH3/EX3.7/Result3_7.txt @@ -0,0 +1,9 @@ +
+ The value of n x and y :
+
+ 0. 1. 1.
+ 1. 1.25 1.75
+ 2. 1.236111 1.581349
+ 3. 1.236068 1.572329
+ 4. 1.236068 1.572303
+ 5. 1.236068 1.572303
\ No newline at end of file diff --git a/191/CH3/EX3.8/Example3_8.sce b/191/CH3/EX3.8/Example3_8.sce new file mode 100755 index 000000000..d1325132a --- /dev/null +++ b/191/CH3/EX3.8/Example3_8.sce @@ -0,0 +1,34 @@ +//Non-Linear Equation
+clc;
+clear;
+close();
+funcprot(0);
+format('v',9);
+deff('[func1]=f(x1,x2)','func1=-2.0625*x1+2*x2-0.0625*x1^3+0.5');
+deff('[func2]=g(x1,x2,x3)','func2=x3-2*x2+x1-0.0625*x2^3+0.125*x2*(x3-x1)');
+deff('[func3]=h(x2,x3,x4)','func3=x4-2*x3+x2-0.0625*x3^3+0.125*x3*(x4-x2)');
+deff('[func4]=k(x3,x4)','func4=-1.9375*x4+x3-0.0625*x4^3-0.125*x3*x4+0.5');
+//define the corresponding partial differenciation of the function = 16
+deff('[difffx1]=fx1(x1)','difffx1=-2.0625-3*0.0625*x1^2');
+deff('[difffx2]=fx2(x2)','difffx2=2');
+
+deff('[diffgx1]=gx1(x2)','diffgx1=1-0.125*x2');
+deff('[diffgx2]=gx2(x1,x2,x3)','diffgx2=-2-3*0.0625*x2^2+0.125*(x3-x1)');
+deff('[diffgx3]=gx3(x2)','diffgx3=1+0.125*x2');
+
+deff('[diffhx2]=hx2(x3)','diffhx2=1-0.125*x3');
+deff('[diffhx3]=hx3(x3,x4)','diffhx3=-2-0.0625*3*x3^2+0.125*x4');
+deff('[diffhx4]=hx4(x3)','diffhx4 = 1+0.125*x3');
+
+deff('[diffkx3]=kx3(x4)','diffkx3=1-0.125*x4');
+deff('[diffkx4]=kx4(x3,x4)','diffkx4=-1.9375-3*0.0625*x4^2-0.125*x3');
+
+x = [1.5 1.25 1.0 0.75]';
+for i=1:6
+ N(i)=i-1;
+ x1(i) = x(1);x2(i)=x(2);x3(i) = x(3);x4(i)=x(4);
+ J = [fx1(x(1)),fx2(x(2)),0,0;gx1(x(2)),gx2(x(1),x(2),x(3)),gx3(x(2)),0;0,hx2(x(3)),hx3(x(3),x(4)),hx4(x(3));0,0,kx3(x(4)),kx4(x(3),x(4))];
+ x = x - inv(J)*[f(x(1),x(2));g(x(1),x(2),x(3));h(x(2),x(3),x(4));k(x(3),x(4))];
+end
+n = [N x1 x2 x3 x4];
+disp(n,'The values of N x1 x2 x3 x4 respectively : ');
\ No newline at end of file diff --git a/191/CH3/EX3.8/Result3_8.txt b/191/CH3/EX3.8/Result3_8.txt new file mode 100755 index 000000000..e2ec3b9f7 --- /dev/null +++ b/191/CH3/EX3.8/Result3_8.txt @@ -0,0 +1,10 @@ +
+ The values of N x1 x2 x3 x4 respectively :
+
+ 0. 1.5 1.25 1. 0.75
+ 1. 1.056454 0.851376 0.684750 0.584436
+ 2. 0.979212 0.788578 0.659124 0.568218
+ 3. 0.979061 0.788984 0.660975 0.569006
+ 4. 0.978892 0.788795 0.660741 0.568901
+ 5. 0.978913 0.788819 0.660771 0.568914
+
\ No newline at end of file |