summaryrefslogtreecommitdiff
path: root/191
diff options
context:
space:
mode:
authorprashantsinalkar2017-10-10 12:38:01 +0530
committerprashantsinalkar2017-10-10 12:38:01 +0530
commitf35ea80659b6a49d1bb2ce1d7d002583f3f40947 (patch)
treeeb72842d800ac1233e9d890e020eac5fd41b0b1b /191
parent7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (diff)
downloadScilab-TBC-Uploads-f35ea80659b6a49d1bb2ce1d7d002583f3f40947.tar.gz
Scilab-TBC-Uploads-f35ea80659b6a49d1bb2ce1d7d002583f3f40947.tar.bz2
Scilab-TBC-Uploads-f35ea80659b6a49d1bb2ce1d7d002583f3f40947.zip
updated the code
Diffstat (limited to '191')
-rwxr-xr-x191/CH3/EX3.6/Example3_6.sce100
-rwxr-xr-x191/CH4/EX4.6/Example4_6.sce42
-rwxr-xr-x191/CH5/EX5.16/Example5_16.sce90
-rwxr-xr-x191/CH6/EX6.1/Example6_1.sce36
-rwxr-xr-x191/CH6/EX6.2/Example6_2.sce40
-rwxr-xr-x191/CH6/EX6.4/Example6_4.sce70
-rwxr-xr-x191/CH6/EX6.5/Example6_5.sce66
-rwxr-xr-x191/CH6/EX6.6/Example6_6.sce56
8 files changed, 250 insertions, 250 deletions
diff --git a/191/CH3/EX3.6/Example3_6.sce b/191/CH3/EX3.6/Example3_6.sce
index 3ac4c3f2d..5ddba45d2 100755
--- a/191/CH3/EX3.6/Example3_6.sce
+++ b/191/CH3/EX3.6/Example3_6.sce
@@ -1,51 +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);
+//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,zeros(length(x),1));
+//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,zeros(length(x),1));
+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/CH4/EX4.6/Example4_6.sce b/191/CH4/EX4.6/Example4_6.sce
index 08c5fe547..51c3a0f77 100755
--- a/191/CH4/EX4.6/Example4_6.sce
+++ b/191/CH4/EX4.6/Example4_6.sce
@@ -1,22 +1,22 @@
-//The Gerchgorin circle
-clc;
-clear;
-close();
-format('v',9);
-x = [0:.1:14];
-plot2d(0,0,-1,"031"," ",[0,-5,14,5]);
-plot(x,0);
-A = [5 1 0;-1 3 1;-2 1 10];
-disp(A,'A = ');
-for i=1:3
- disp(A(i,i),'Centers are : ');
- radius = 0;
- for j=1:3
- if j~=i then
- radius = radius + abs(A(i,j));
- end
- end
- disp(radius,'Radius : ');
- xarc(A(i,i)-radius,radius,2*radius,2*radius,0,360*64);
-end
+//The Gerchgorin circle
+clc;
+clear;
+close();
+format('v',9);
+x = [0:.1:14];
+plot2d(0,0,-1,"031"," ",[0,-5,14,5]);
+plot(x,zeros(length(x),1));
+A = [5 1 0;-1 3 1;-2 1 10];
+disp(A,'A = ');
+for i=1:3
+ disp(A(i,i),'Centers are : ');
+ radius = 0;
+ for j=1:3
+ if j~=i then
+ radius = radius + abs(A(i,j));
+ end
+ end
+ disp(radius,'Radius : ');
+ xarc(A(i,i)-radius,radius,2*radius,2*radius,0,360*64);
+end
disp('The figure indicates that 2 of the eigenvalues of A lie inside the intersected region of 2 circles, and the remaining eigen value in the other circle.'); \ No newline at end of file
diff --git a/191/CH5/EX5.16/Example5_16.sce b/191/CH5/EX5.16/Example5_16.sce
index a246a8985..1cd2060b7 100755
--- a/191/CH5/EX5.16/Example5_16.sce
+++ b/191/CH5/EX5.16/Example5_16.sce
@@ -1,45 +1,45 @@
-//Least square approximation to continuous functions
-clc;
-clear;
-close();
-format('v',8);
-funcprot(0);
-deff('[g]=f(x,y)','g= -y^2/(1+x)');
-disp('approximation of e^x on [0,1] with a uniform weight w(x)=1')
-a11 = integrate('1','x',0,1);
-a12 = integrate('x','x',0,1);
-a13 = integrate('x*x','x',0,1);
-a14 = integrate('x^3','x',0,1);
-a21 = integrate('x','x',0,1);
-a22 = integrate('x^2','x',0,1);
-a23 = integrate('x^3','x',0,1);
-a24 = integrate('x^4','x',0,1);
-a31 = integrate('x^2','x',0,1);
-a32 = integrate('x^3','x',0,1);
-a33 = integrate('x^4','x',0,1);
-a34 = integrate('x^5','x',0,1);
-a41 = integrate('x^3','x',0,1);
-a42 = integrate('x^4','x',0,1);
-a43 = integrate('x^5','x',0,1);
-a44 = integrate('x^6','x',0,1);
-
-c1 = integrate('exp(x)','x',0,1);
-c2 = integrate('x*exp(x)','x',0,1);
-c3 = integrate('x^2*exp(x)','x',0,1);
-c4 = integrate('x^3*exp(x)','x',0,1);
-
-A = [a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34;a41 a42 a43 a44];
-C = [c1;c2;c3;c4];
-ann = inv(A)*C;
-disp(ann, 'The coefficients a0,a1,a2,a3 are respectively : ' );
-
-deff('[px]=p3(x)','px=ann(4)*x^3+ann(3)*x^2+ann(2)*x+ann(1)');
-x = [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]';
-e = exp(x);
-p = p3(x);
-err = e-p;
-ann = [x e p err];
-
-disp(ann,'Displaying the value of x exp(x) p3(x) exp(x)-p3(x) :');
-plot(x,err);
-plot(x,0); \ No newline at end of file
+//Least square approximation to continuous functions
+clc;
+clear;
+close();
+format('v',8);
+funcprot(0);
+deff('[g]=f(x,y)','g= -y^2/(1+x)');
+disp('approximation of e^x on [0,1] with a uniform weight w(x)=1')
+a11 = integrate('1','x',0,1);
+a12 = integrate('x','x',0,1);
+a13 = integrate('x*x','x',0,1);
+a14 = integrate('x^3','x',0,1);
+a21 = integrate('x','x',0,1);
+a22 = integrate('x^2','x',0,1);
+a23 = integrate('x^3','x',0,1);
+a24 = integrate('x^4','x',0,1);
+a31 = integrate('x^2','x',0,1);
+a32 = integrate('x^3','x',0,1);
+a33 = integrate('x^4','x',0,1);
+a34 = integrate('x^5','x',0,1);
+a41 = integrate('x^3','x',0,1);
+a42 = integrate('x^4','x',0,1);
+a43 = integrate('x^5','x',0,1);
+a44 = integrate('x^6','x',0,1);
+
+c1 = integrate('exp(x)','x',0,1);
+c2 = integrate('x*exp(x)','x',0,1);
+c3 = integrate('x^2*exp(x)','x',0,1);
+c4 = integrate('x^3*exp(x)','x',0,1);
+
+A = [a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34;a41 a42 a43 a44];
+C = [c1;c2;c3;c4];
+ann = inv(A)*C;
+disp(ann, 'The coefficients a0,a1,a2,a3 are respectively : ' );
+
+deff('[px]=p3(x)','px=ann(4)*x.^3+ann(3)*x.^2+ann(2)*x+ann(1)');
+x = [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]';
+e = exp(x);
+p = p3(x);
+err = e-p;
+ann = [x e p err];
+
+disp(ann,'Displaying the value of x exp(x) p3(x) exp(x)-p3(x) :');
+plot(x,err);
+plot(x,zeros(length(x),1)); \ No newline at end of file
diff --git a/191/CH6/EX6.1/Example6_1.sce b/191/CH6/EX6.1/Example6_1.sce
index 56f64a982..7ec725bea 100755
--- a/191/CH6/EX6.1/Example6_1.sce
+++ b/191/CH6/EX6.1/Example6_1.sce
@@ -1,19 +1,19 @@
-//Numerical Differentiation
-clc;
-clear;
-close();
-format('v',9);
-deff('[y]=f(x)','y=exp(-x)');
-
-x0 = ones(:,8);
-h = [1 .2 .1 .02 .01 .002 .001 .0002];
-x1 = 1+h;
-f0 = f(x0);
-f1 = f(x1);
-dif = (f1-f0)./h;
-max_trun_err = exp(-1).*h/2;
-act_err = abs(- exp(-1)-dif);
-answer = [h' f0' f1' dif' max_trun_err' act_err'];
-disp(answer,' h f0 f1 f1-f0/h he^-1 |Actual Error|');
-x = (0:.0002:3);
+//Numerical Differentiation
+clc;
+clear;
+close();
+format('v',9);
+deff('[y]=f(x)','y=exp(-x)');
+
+x0 = ones(1,8);
+h = [1 .2 .1 .02 .01 .002 .001 .0002];
+x1 = 1+h;
+f0 = f(x0);
+f1 = f(x1);
+dif = (f1-f0)./h;
+max_trun_err = exp(-1).*h/2;
+act_err = abs(- exp(-1)-dif);
+answer = [h' f0' f1' dif' max_trun_err' act_err'];
+disp(answer,' h f0 f1 f1-f0/h he^-1 |Actual Error|');
+x = (0:.0002:3);
plot(x,f(x)); \ No newline at end of file
diff --git a/191/CH6/EX6.2/Example6_2.sce b/191/CH6/EX6.2/Example6_2.sce
index d4604caea..1779ff2e4 100755
--- a/191/CH6/EX6.2/Example6_2.sce
+++ b/191/CH6/EX6.2/Example6_2.sce
@@ -1,21 +1,21 @@
-//Numerical Differentiation
-clc;
-clear;
-close();
-format('v',9);
-deff('[y]=f(x)','y=exp(-x)');
-h = [1 .2 .1 .02 .01 .002 .001 .0002];
-x0 = 1 - h;
-x1 = ones(:,8);
-x2 = 1+h;
-f0 = f(x0);
-f1 = f(x1);
-f2 = f(x2);
-dif = (f2-f0)./(2*h);
-max_trun_err = exp(h-1).*h^2/6;
-act_err = abs(- exp(-1)-dif);
-answer = [h' f0' f2' dif' max_trun_err' act_err'];
-disp(answer,' h f0 f2 f2-f0/2h h^2*exp(h-1)/6 |Actual Error|');
-disp('truncation error does not exceed h^2*exp(h-1)/6')
-x = (0:.0002:3);
+//Numerical Differentiation
+clc;
+clear;
+close();
+format('v',9);
+deff('[y]=f(x)','y=exp(-x)');
+h = [1 .2 .1 .02 .01 .002 .001 .0002];
+x0 = 1 - h;
+x1 = ones(1,8);
+x2 = 1+h;
+f0 = f(x0);
+f1 = f(x1);
+f2 = f(x2);
+dif = (f2-f0)./(2*h);
+max_trun_err = exp(h-1).*h.^2/6;
+act_err = abs(- exp(-1)-dif);
+answer = [h' f0' f2' dif' max_trun_err' act_err'];
+disp(answer,' h f0 f2 f2-f0/2h h^2*exp(h-1)/6 |Actual Error|');
+disp('truncation error does not exceed h^2*exp(h-1)/6')
+x = (0:.0002:3);
plot(x,f(x)); \ No newline at end of file
diff --git a/191/CH6/EX6.4/Example6_4.sce b/191/CH6/EX6.4/Example6_4.sce
index 58ccab6b6..7c61fe699 100755
--- a/191/CH6/EX6.4/Example6_4.sce
+++ b/191/CH6/EX6.4/Example6_4.sce
@@ -1,36 +1,36 @@
-//Newton Cotes formula
-clc;
-clear;
-close();
-format('v',9);
-funcprot(0);
-disp('Integral 0 to PI/4 x*cos dx');
-disp('based on open Newton-Cotes formulas ');
-
-deff('[y]=f(x)','y=x*cos(x)');
-
-k = [0 1 2 3]
-
-a = 0;
-b = %pi/4;
-h = (ones(:,4)*(b-a))./(k+2);
-x0 = a+h;
-xk = b-h;
-
-k(1) = 2*h(1)*f(h(1));
-disp(k(1),'k=0');
-
-k(2) = 3*h(2)*(f(h(2))+f(2*h(2)))/2;
-disp(k(2),'k=1');
-
-k(3) = 4*h(3)*(2*f(h(3))-f(2*h(3))+2*f(3*h(3)))/3;
-disp(k(3),'k=2');
-
-k(4) = 5*h(4)*(11*f(h(4))+f(2*h(4))+f(3*h(4))+11*f(4*h(4)))/24;
-disp(k(4),'k=3');
-
-exact = integrate('x*cos(x)','x',0,%pi/4);
-disp(exact,'The exact value of intergation is :');
-exact = ones(:,4)*exact;
-err = exact-k;
+//Newton Cotes formula
+clc;
+clear;
+close();
+format('v',9);
+funcprot(0);
+disp('Integral 0 to PI/4 x*cos dx');
+disp('based on open Newton-Cotes formulas ');
+
+deff('[y]=f(x)','y=x*cos(x)');
+
+k = [0 1 2 3]
+
+a = 0;
+b = %pi/4;
+h = (ones(1,4)*(b-a))./(k+2);
+x0 = a+h;
+xk = b-h;
+
+k(1) = 2*h(1)*f(h(1));
+disp(k(1),'k=0');
+
+k(2) = 3*h(2)*(f(h(2))+f(2*h(2)))/2;
+disp(k(2),'k=1');
+
+k(3) = 4*h(3)*(2*f(h(3))-f(2*h(3))+2*f(3*h(3)))/3;
+disp(k(3),'k=2');
+
+k(4) = 5*h(4)*(11*f(h(4))+f(2*h(4))+f(3*h(4))+11*f(4*h(4)))/24;
+disp(k(4),'k=3');
+
+exact = integrate('x*cos(x)','x',0,%pi/4);
+disp(exact,'The exact value of intergation is :');
+exact = ones(1,4)*exact;
+err = exact-k;
disp(err','thus corresponding errors are : '); \ No newline at end of file
diff --git a/191/CH6/EX6.5/Example6_5.sce b/191/CH6/EX6.5/Example6_5.sce
index 70049cb6b..5939f4518 100755
--- a/191/CH6/EX6.5/Example6_5.sce
+++ b/191/CH6/EX6.5/Example6_5.sce
@@ -1,34 +1,34 @@
-//Trapezoidal Rule
-clc;
-clear;
-close();
-format('v',10);
-funcprot(0);
-disp('Integral 0 to 2 e^x dx');
-disp('based on trapezoidal rule ');
-
-deff('[y]=f(x)','y=exp(x)');
-
-n = [1 2 4 8];
-
-a = 0;
-b = 2;
-h = (ones(:,4)*(b-a))./n;
-
-t(1) = h(1)*(f(a)+f(b))/2;
-disp(t(1),'n=1');
-
-t(2) = h(2)*(f(a)+f(b)+2*f(h(2)))/2;
-disp(t(2),'n=2');
-
-t(3) = h(3)*(f(a)+f(b)+2*(f(h(3))+f(2*h(3))+f(3*h(3))))/2;
-disp(t(3),'n=4');
-
-t(4) = h(4)*(f(a)+f(b)+2*(f(h(4))+f(2*h(4))+f(3*h(4))+f(4*h(4))+f(5*h(4))+f(6*h(4))+f(7*h(4))))/2;
-disp(t(4),'n=8');
-
-exact = integrate('exp(x)','x',0,2);
-disp(exact,'The exact value of intergation is :');
-exact = ones(4)*exact;
-err = exact-t;
+//Trapezoidal Rule
+clc;
+clear;
+close();
+format('v',10);
+funcprot(0);
+disp('Integral 0 to 2 e^x dx');
+disp('based on trapezoidal rule ');
+
+deff('[y]=f(x)','y=exp(x)');
+
+n = [1 2 4 8];
+
+a = 0;
+b = 2;
+h = (ones(1,4)*(b-a))./n;
+
+t(1) = h(1)*(f(a)+f(b))/2;
+disp(t(1),'n=1');
+
+t(2) = h(2)*(f(a)+f(b)+2*f(h(2)))/2;
+disp(t(2),'n=2');
+
+t(3) = h(3)*(f(a)+f(b)+2*(f(h(3))+f(2*h(3))+f(3*h(3))))/2;
+disp(t(3),'n=4');
+
+t(4) = h(4)*(f(a)+f(b)+2*(f(h(4))+f(2*h(4))+f(3*h(4))+f(4*h(4))+f(5*h(4))+f(6*h(4))+f(7*h(4))))/2;
+disp(t(4),'n=8');
+
+exact = integrate('exp(x)','x',0,2);
+disp(exact,'The exact value of intergation is :');
+exact = ones(4)*exact;
+err = exact-t;
disp(err,'thus corresponding errors are : '); \ No newline at end of file
diff --git a/191/CH6/EX6.6/Example6_6.sce b/191/CH6/EX6.6/Example6_6.sce
index f3588ed84..2a21689ac 100755
--- a/191/CH6/EX6.6/Example6_6.sce
+++ b/191/CH6/EX6.6/Example6_6.sce
@@ -1,29 +1,29 @@
-//Simpson Rule
-clc;
-clear;
-close();
-format('v',10);
-funcprot(0);
-
-deff('[y]=f(x)','y=exp(x)');
-
-n = [1 2 4];
-
-a = 0;
-b = 2;
-h = (ones(:,3)*(b-a))./(2*n);
-
-s(1) = h(1)*(f(a)+f(b)+4*f(h(1)))/3;
-disp(s(1),'n=1');
-
-s(2) = h(2)*(f(a)+f(b)+2*f(2*h(2))+4*(f(h(2))+f(3*h(2))))/3;
-disp(s(2),'n=2');
-
-s(3) = h(3)*(f(a)+f(b)+2*(f(2*h(3))+f(4*h(3))+f(6*h(3)))+4*(f(h(3))+f(3*h(3))+f(5*h(3))+f(7*h(3))))/3;
-disp(s(3),'n=4');
-
-exact = integrate('exp(x)','x',0,2);
-disp(exact,'The exact value of intergation is :');
-exact = ones(3)*exact;
-err = exact-s;
+//Simpson Rule
+clc;
+clear;
+close();
+format('v',10);
+funcprot(0);
+
+deff('[y]=f(x)','y=exp(x)');
+
+n = [1 2 4];
+
+a = 0;
+b = 2;
+h = (ones(1,3)*(b-a))./(2*n);
+
+s(1) = h(1)*(f(a)+f(b)+4*f(h(1)))/3;
+disp(s(1),'n=1');
+
+s(2) = h(2)*(f(a)+f(b)+2*f(2*h(2))+4*(f(h(2))+f(3*h(2))))/3;
+disp(s(2),'n=2');
+
+s(3) = h(3)*(f(a)+f(b)+2*(f(2*h(3))+f(4*h(3))+f(6*h(3)))+4*(f(h(3))+f(3*h(3))+f(5*h(3))+f(7*h(3))))/3;
+disp(s(3),'n=4');
+
+exact = integrate('exp(x)','x',0,2);
+disp(exact,'The exact value of intergation is :');
+exact = ones(3)*exact;
+err = exact-s;
disp(err,'thus corresponding errors are : '); \ No newline at end of file