diff options
Diffstat (limited to '1670/CH6')
-rwxr-xr-x | 1670/CH6/EX6.10/6_10.sce | 29 | ||||
-rwxr-xr-x | 1670/CH6/EX6.11/6_11.sce | 29 | ||||
-rwxr-xr-x | 1670/CH6/EX6.12/6_12.sce | 27 | ||||
-rwxr-xr-x | 1670/CH6/EX6.2/6_2.sce | 37 | ||||
-rwxr-xr-x | 1670/CH6/EX6.3/6_3.sce | 30 | ||||
-rwxr-xr-x | 1670/CH6/EX6.4/6_4.sce | 16 | ||||
-rwxr-xr-x | 1670/CH6/EX6.5/6_5.sce | 35 | ||||
-rwxr-xr-x | 1670/CH6/EX6.6/6_6.sce | 18 | ||||
-rwxr-xr-x | 1670/CH6/EX6.7/6_7.sce | 29 | ||||
-rwxr-xr-x | 1670/CH6/EX6.8/6_8.sce | 32 | ||||
-rwxr-xr-x | 1670/CH6/EX6.9/6_9.sce | 29 |
11 files changed, 311 insertions, 0 deletions
diff --git a/1670/CH6/EX6.10/6_10.sce b/1670/CH6/EX6.10/6_10.sce new file mode 100755 index 000000000..c43d236c6 --- /dev/null +++ b/1670/CH6/EX6.10/6_10.sce @@ -0,0 +1,29 @@ +//Example 6.10
+//Least Square Fit
+//Page no. 224
+clc;close;clear;
+
+x=[1,2,3,4]
+y=[0.3,0.64,1.32,5.4]
+n=1;
+printf('\t\t 2\t 3\t 4\t\t\t 2\n n\tx\tx\tx\tx\ty\txy\tx y\n----------------------------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;x5=0;x6=0;x7=0;x8=0;
+for i=1:4
+ printf(' %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',n,x(i),x(i)^2,x(i)^3,x(i)^4,y(i),y(i)*x(i),x(i)^2*y(i))
+ x1=x1+n;
+ x2=x2+x(i);
+ x3=x3+x(i)^2;
+ x4=x4+x(i)^3;
+ x5=x5+x(i)^4;
+ x6=x6+y(i);
+ x7=x7+y(i)*x(i);
+ x8=x8+x(i)^2*y(i)
+end
+printf('----------------------------------------------------------------\n %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',x1,x2,x3,x4,x5,x6,x7,x8)
+A=[x1,x2,x3;x2,x3,x4;x3,x4,x5]
+B=[x6;x7;x8]
+C=inv(A)*B;
+disp(C)
+x=poly(0,'x')
+y=C(1)+C(2)*x+C(3)*x^2
+disp(y,'y =')
\ No newline at end of file diff --git a/1670/CH6/EX6.11/6_11.sce b/1670/CH6/EX6.11/6_11.sce new file mode 100755 index 000000000..5f9cc5db9 --- /dev/null +++ b/1670/CH6/EX6.11/6_11.sce @@ -0,0 +1,29 @@ +//Example 6.9
+//Least Square Fit
+//Page no. 224
+clc;close;clear;
+
+x=[2,4,6,8,10]
+y=[3.07,12.85,31.47,57.38,91.29]
+n=1;
+printf('\t\t 2\t 3\t 4\t\t\t 2\n n\tx\tx\tx\tx\ty\txy\tx y\n----------------------------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;x5=0;x6=0;x7=0;x8=0;
+for i=1:5
+ printf(' %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',n,x(i),x(i)^2,x(i)^3,x(i)^4,y(i),y(i)*x(i),x(i)^2*y(i))
+ x1=x1+n;
+ x2=x2+x(i);
+ x3=x3+x(i)^2;
+ x4=x4+x(i)^3;
+ x5=x5+x(i)^4;
+ x6=x6+y(i);
+ x7=x7+y(i)*x(i);
+ x8=x8+x(i)^2*y(i)
+end
+printf('----------------------------------------------------------------\n %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',x1,x2,x3,x4,x5,x6,x7,x8)
+A=[x1,x2,x3;x2,x3,x4;x3,x4,x5]
+B=[x6;x7;x8]
+C=inv(A)*B;
+disp(C)
+x=poly(0,'x')
+y=C(1)+C(2)*x+C(3)*x^2
+disp(y,'y =')
\ No newline at end of file diff --git a/1670/CH6/EX6.12/6_12.sce b/1670/CH6/EX6.12/6_12.sce new file mode 100755 index 000000000..bc040078d --- /dev/null +++ b/1670/CH6/EX6.12/6_12.sce @@ -0,0 +1,27 @@ +//Example 6.12
+//Least Square Fit
+//Page no. 224
+clc;close;clear;
+
+x=[10,20,30,40,50]
+y=[8,10,15,21,30]
+n=1;
+printf('\t\t 2\t 4\t\t\t 2\n n\tx\tx\tx\t\ty\tx y\n----------------------------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;x5=0;x6=0;x7=0;x8=0;
+for i=1:5
+ printf(' %g\t%g\t%g\t%.9g\t\t%g\t%g\n',n,x(i),x(i)^2,x(i)^4,y(i),x(i)^2*y(i))
+ x1=x1+n;
+ x2=x2+x(i);
+ x3=x3+x(i)^2;
+ x4=x4+x(i)^4;
+ x5=x5+y(i);
+ x6=x6+x(i)^2*y(i)
+end
+printf('----------------------------------------------------------------\n %g\t%g\t%g\t%.9g\t\t%g\t%g\n',x1,x2,x3,x4,x5,x6)
+A=[x1,x3;x3,x4;]
+B=[x5;x6]
+C=inv(A)*B;
+disp(C)
+x=poly(0,'x')
+y=C(1)+C(2)*x^2
+disp(y,'y =')
\ No newline at end of file diff --git a/1670/CH6/EX6.2/6_2.sce b/1670/CH6/EX6.2/6_2.sce new file mode 100755 index 000000000..920a9a820 --- /dev/null +++ b/1670/CH6/EX6.2/6_2.sce @@ -0,0 +1,37 @@ +//Example 6.2
+//Least Line Square Approximation
+//Page no. 216
+clc;close;clear;
+
+x=[2;5;6;9;11];
+y=[2;4;6;9;10];n=1;
+printf('\t 2\t\t\t 2\nn\tx\tx\ty\txy\ty\n--------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;x5=0;x6=0;
+for i=1:5
+ printf(' %i\t%i\t%i\t%i\t%i\t%i\n',n,x(i),x(i)^2,y(i),x(i)*y(i),y(i)^2)
+ x1=x1+n;
+ x2=x2+x(i);
+ x3=x3+x(i)^2;
+ x4=x4+y(i);
+ x5=x5+x(i)*y(i);
+ x6=x6+y(i)^2;
+end
+printf('--------------------------------------------\n %i\t%i\t%i\t%i\t%i\t%i\n',x1,x2,x3,x4,x5,x6)
+
+A=[x1,x2;x2,x3]
+B=[x4;x5]
+C=inv(A)*B;
+x7=poly(0,'x')
+y=C(1)+C(2)*x7
+disp(y,'y=')
+x0=x2/x1;
+y0=x4/x1;
+A=x3-x1*x0^2;
+B=x5-x1*x0*y0;
+C=x6-x1*y0^2;
+x7=poly(0,'b')
+y=x7^2+(A-C)*x7/B-1
+b=roots(y)
+a=y0-b(2)*x0
+x7=poly(0,'x')
+disp('is the required least line',a+b(2)*x7,'y = ')
\ No newline at end of file diff --git a/1670/CH6/EX6.3/6_3.sce b/1670/CH6/EX6.3/6_3.sce new file mode 100755 index 000000000..5d4813185 --- /dev/null +++ b/1670/CH6/EX6.3/6_3.sce @@ -0,0 +1,30 @@ +//Example 6.3
+//Least Square Method
+//Page no. 217
+clc;close;clear;
+
+x=[1,2,3,4,5,6,7,8];
+y=[3,3,4,5,5,6,6,7];n=1;
+printf('\t 2\t\t 2\n n\tx\tx\ty\txy\ty\n--------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;x5=0;x6=0;
+for i=1:8
+ printf(' %i\t%i\t%i\t%i\t%i\t%i\n',n,x(i),x(i)^2,y(i),x(i)*y(i),y(i)^2)
+ x1=x1+n;
+ x2=x2+x(i);
+ x3=x3+x(i)^2;
+ x4=x4+y(i);
+ x5=x5+x(i)*y(i);
+ x6=x6+y(i)^2;
+end
+printf('--------------------------------------------\n %i\t%i\t%i\t%i\t%i\t%i\n',x1,x2,x3,x4,x5,x6)
+x0=x2/x1;
+y0=x4/x1;
+A=x3-x1*x0^2;
+B=x5-x1*x0*y0;
+C=x6-x1*y0^2;
+x7=poly(0,'b')
+y=x7^2+(A-C)*x7/B-1
+b=roots(y)
+a=y0-b(2)*x0
+x7=poly(0,'x')
+disp('is the required least line',a+b(2)*x7,'y = ')
\ No newline at end of file diff --git a/1670/CH6/EX6.4/6_4.sce b/1670/CH6/EX6.4/6_4.sce new file mode 100755 index 000000000..8f235ae9e --- /dev/null +++ b/1670/CH6/EX6.4/6_4.sce @@ -0,0 +1,16 @@ +//Example 6.4
+//Least Square Method
+//Page no. 219
+clc;close;clear;
+
+t=[0.2,0.4,0.6,0.8,1]
+h=[0.196,0.785,1.7665,3.1406,4.9075]
+m=2;
+for i=1:5
+ t1(i)=t(i)^(2*m)
+ h1(i)=h(i)*t(i)^2
+end
+g=sum(h1)/sum(t1)
+disp(g,'y = ')
+g=g*2
+disp(g,'Gravitational Constatnt :')
\ No newline at end of file diff --git a/1670/CH6/EX6.5/6_5.sce b/1670/CH6/EX6.5/6_5.sce new file mode 100755 index 000000000..3165ec099 --- /dev/null +++ b/1670/CH6/EX6.5/6_5.sce @@ -0,0 +1,35 @@ +//Example 6.5
+//Power Fit Method
+//Page no. 220
+clc;close;clear;
+
+x=[2,2.3,2.6,2.9,3.2]
+y=[5.1,7.5,10.6,14.4,19]
+printf('\t 2\t 3\t 4\t 6\t\t 2\t 3\n x\tx\tx\tx\tx\ty\tyx\tyx\n----------------------------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;
+for i=1:5
+ printf(' %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',x(i),x(i)^2,x(i)^3,x(i)^4,x(i)^6,y(i),x(i)^2*y(i),y(i)*x(i)^3)
+ x1=x1+x(i)^4;
+ x2=x2+x(i)^6;
+ x3=x3+x(i)^2*y(i);
+ x4=x4+y(i)*x(i)^3;
+end
+printf('----------------------------------------------------------------\n \t\t\t%g\t%g\t\t%g\t%g\n',x1,x2,x3,x4)
+a(1)=x3/x1;
+x5=poly(0,'x')
+disp(a(1)*x5^2,'The power fit, y =')
+a(2)=x4/x2;
+disp(a(2)*x5^3,'The power fit, y =')
+e=[0,0]
+for i=1:2
+ for j=1:5
+ e(i)=e(i)+(a(i)*x(j)^(i+1)-y(j))^2
+ end
+ e(i)=sqrt(e(i)/5)
+ printf('\n\nerror%i = %.2g\n',i,e(i))
+end
+if e(1)>e(2) then
+ disp(a(2)*x5^3,'y = ','Hence the best power fir curve is')
+else
+ disp(a(1)*x5^2,'y = ','Hence the best power fir curve is')
+end
\ No newline at end of file diff --git a/1670/CH6/EX6.6/6_6.sce b/1670/CH6/EX6.6/6_6.sce new file mode 100755 index 000000000..3f92b9860 --- /dev/null +++ b/1670/CH6/EX6.6/6_6.sce @@ -0,0 +1,18 @@ +//Example 6.6
+//Least Square Method
+//Page no. 221
+clc;close;clear;
+
+x=[2,3,4,5];
+y=[27.8,62.1,110,161];
+printf('\t 2\t 4\t\t 2\nx\tx\tx\ty\tyx\n----------------------------------------\n')
+x1=0;x2=0;
+for i=1:4
+ printf(' %g\t%g\t%g\t%g\t%g\n',x(i),x(i)^2,x(i)^4,y(i),y(i)*x(i)^2)
+ x1=x1+x(i)^4;
+ x2=x2+y(i)*x(i)^2;
+end
+printf('----------------------------------------\n \t\t%g\t\t%g\n',x1,x2)
+a=x2/x1;
+x1=poly(0,'x')
+disp(a*x1^2,'y = ')
\ No newline at end of file diff --git a/1670/CH6/EX6.7/6_7.sce b/1670/CH6/EX6.7/6_7.sce new file mode 100755 index 000000000..09b803d1c --- /dev/null +++ b/1670/CH6/EX6.7/6_7.sce @@ -0,0 +1,29 @@ +//Example 6.7
+//Parabola Best Fit
+//Page no. 222
+clc;close;clear;
+
+x=[0,1,2,3,4]
+y=[-2.1,-0.4,2.1,3.6,9.9]
+n=1;
+printf('\t\t 2\t 3\t 4\t\t\t 2\n n\tx\tx\tx\tx\ty\txy\tx y\n----------------------------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;x5=0;x6=0;x7=0;x8=0;
+for i=1:5
+ printf(' %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',n,x(i),x(i)^2,x(i)^3,x(i)^4,y(i),y(i)*x(i),x(i)^2*y(i))
+ x1=x1+n;
+ x2=x2+x(i);
+ x3=x3+x(i)^2;
+ x4=x4+x(i)^3;
+ x5=x5+x(i)^4;
+ x6=x6+y(i);
+ x7=x7+y(i)*x(i);
+ x8=x8+x(i)^2*y(i)
+end
+printf('----------------------------------------------------------------\n %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',x1,x2,x3,x4,x5,x6,x7,x8)
+A=[x1,x2,x3;x2,x3,x4;x3,x4,x5]
+B=[x6;x7;x8]
+C=inv(A)*B;
+disp(C)
+x=poly(0,'x')
+y=C(1)+C(2)*x+C(3)*x^2
+disp(y,'y =')
\ No newline at end of file diff --git a/1670/CH6/EX6.8/6_8.sce b/1670/CH6/EX6.8/6_8.sce new file mode 100755 index 000000000..47d53fb8c --- /dev/null +++ b/1670/CH6/EX6.8/6_8.sce @@ -0,0 +1,32 @@ +//Example 6.8
+//Parabola Best Fit
+//Page no. 223
+clc;close;clear;
+
+x=[0.78,1.56,2.34,3.12,3.81]
+y=[2.5,1.2,1.12,2.25,4.28]
+n=1;
+for i=1:5
+ x(i)=(x(i)-2.34)/0.78
+end
+printf('\t\t 2\t 3\t 4\t\t\t 2\n n\tX\tX\tX\tX\ty\tXy\tX y\n----------------------------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;x5=0;x6=0;x7=0;x8=0;
+for i=1:5
+ printf(' %.2g\t%.2g\t%.2g\t%.2g\t%.2g\t%.2g\t%.2g\t%.2g\n',n,x(i),x(i)^2,x(i)^3,x(i)^4,y(i),y(i)*x(i),x(i)^2*y(i))
+ x1=x1+n;
+ x2=x2+x(i);
+ x3=x3+x(i)^2;
+ x4=x4+x(i)^3;
+ x5=x5+x(i)^4;
+ x6=x6+y(i);
+ x7=x7+y(i)*x(i);
+ x8=x8+x(i)^2*y(i)
+end
+printf('----------------------------------------------------------------\n %.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n',x1,x2,x3,x4,x5,x6,x7,x8)
+A=[x1,x2,x3;x2,x3,x4;x3,x4,x5]
+B=[x6;x7;x8]
+C=inv(A)*B;
+disp(C)
+x=poly(0,'X')
+y=C(1)+C(2)*x+C(3)*x^2
+disp(y,'y =')
\ No newline at end of file diff --git a/1670/CH6/EX6.9/6_9.sce b/1670/CH6/EX6.9/6_9.sce new file mode 100755 index 000000000..c762ade5a --- /dev/null +++ b/1670/CH6/EX6.9/6_9.sce @@ -0,0 +1,29 @@ +//Example 6.9
+//Least Square Fit
+//Page no. 224
+clc;close;clear;
+
+x=[-3,-1,1,3]
+y=[15,5,1,5]
+n=1;
+printf('\t\t 2\t 3\t 4\t\t\t 2\n n\tx\tx\tx\tx\ty\txy\tx y\n----------------------------------------------------------------\n')
+x1=0;x2=0;x3=0;x4=0;x5=0;x6=0;x7=0;x8=0;
+for i=1:4
+ printf(' %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',n,x(i),x(i)^2,x(i)^3,x(i)^4,y(i),y(i)*x(i),x(i)^2*y(i))
+ x1=x1+n;
+ x2=x2+x(i);
+ x3=x3+x(i)^2;
+ x4=x4+x(i)^3;
+ x5=x5+x(i)^4;
+ x6=x6+y(i);
+ x7=x7+y(i)*x(i);
+ x8=x8+x(i)^2*y(i)
+end
+printf('----------------------------------------------------------------\n %g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n',x1,x2,x3,x4,x5,x6,x7,x8)
+A=[x1,x2,x3;x2,x3,x4;x3,x4,x5]
+B=[x6;x7;x8]
+C=inv(A)*B;
+disp(C)
+x=poly(0,'x')
+y=C(1)+C(2)*x+C(3)*x^2
+disp(y,'y =')
\ No newline at end of file |