diff options
Diffstat (limited to '413')
58 files changed, 1588 insertions, 0 deletions
diff --git a/413/CH1/EX1.1/Table_1.sce b/413/CH1/EX1.1/Table_1.sce new file mode 100644 index 000000000..387fe3f9b --- /dev/null +++ b/413/CH1/EX1.1/Table_1.sce @@ -0,0 +1,20 @@ +//The bisection method for f(x)=3*x+sin(x)-exp(x), starting from 0 and 1 in 13 iterations)
+
+clearglobal()
+clc;
+fx='3*x+sin(x)-exp(x)'//Define function here
+xa=0; // intial value
+xb=1; // final vale where root need to bracket
+n=13; // no. of iterations
+x = xa; fa=eval(fx);
+x = xb; fb=eval(fx);
+ for i=1:n
+ xc = (xa+xb)/2; x = xc; fc = eval(fx);
+ X = [i,xa,xb,xc,fc];
+ disp(X)
+ if fc*fa < 0 then
+ xb = xc;
+ else xa = xc;
+ end;
+ end;
+
diff --git a/413/CH1/EX1.2/Table2.sce b/413/CH1/EX1.2/Table2.sce new file mode 100644 index 000000000..45015c2db --- /dev/null +++ b/413/CH1/EX1.2/Table2.sce @@ -0,0 +1,28 @@ +//The secant method for f(x)=3*x+sin(x)-exp(x), starting from 0 and 1 )
+clearglobal()
+clc;
+fx='3*x+sin(x)-exp(x)'//Define function here
+x0=0;// intial value
+x1=1;// second vale
+x2=4; //just to start loop
+tol=0.0000001; // tolerence value
+x = x0; fa=eval(fx);
+x = x1; fb=eval(fx);
+x = x2; fc=eval(fx);
+i=1;
+while abs(fc)>tol
+ if abs(fa)<abs(fb) then
+ xc=x0;
+ x0=x1;
+ x1=xc;
+ end
+ x = x0; fa=eval(fx);
+ x = x1; fb=eval(fx);
+ x2=x1-fb*(x0-x1)/(fa-fb);
+ x = x2; fc=eval(fx);
+ X = [i,x0,x1,x2,fc];
+ disp(X)
+ x0=x1;
+ x1=x2;
+ i=i+1;
+end;
\ No newline at end of file diff --git a/413/CH1/EX1.3/Table_3.sce b/413/CH1/EX1.3/Table_3.sce new file mode 100644 index 000000000..549db769f --- /dev/null +++ b/413/CH1/EX1.3/Table_3.sce @@ -0,0 +1,28 @@ +//The regula falsi method for f(x)=3*x+sin(x)-exp(x), starting from 0 and 1
+clearglobal()
+clc;
+fx='3*x+sin(x)-exp(x)' //Define function here
+x0=0; // intial value
+x1=1;// final vale where root need to bracket
+x2=4;//just to start loop
+x = x0; fa=eval(fx);
+x = x1; fb=eval(fx);
+tol=0.0000001;
+x = x2; fc=eval(fx);
+i=1;
+if fa*fb<0 then
+while abs(fc)>tol
+ x = x0; fa=eval(fx);
+ x = x1; fb=eval(fx);
+
+ x2=x1-fb*(x0-x1)/(fa-fb);
+ x = x2; fc=eval(fx);
+ X = [i,x0,x1,x2,fc];
+ disp(X)
+ if fc*fa < 0 then
+ x1 = x2;
+ else x0 = x2;
+ end;
+ i=i+1;
+end;
+end
\ No newline at end of file diff --git a/413/CH1/EX1.4/Example_1.sce b/413/CH1/EX1.4/Example_1.sce new file mode 100644 index 000000000..b92d1239e --- /dev/null +++ b/413/CH1/EX1.4/Example_1.sce @@ -0,0 +1,14 @@ +clearglobal()
+clc;
+fx='x.^3+2*x.^2-x+5'
+dfx='3*x.^2+4*x-1'
+x0=2.5;
+x = x0; fa=eval(fx);
+tol=0.0000001
+while abs(fa)>tol
+x = x0; fa=eval(fx); dfa=eval(dfx)
+x1=x0-fa/dfa;
+ X = [x0,x1];
+ disp(X)
+ x0=x1
+ end;
\ No newline at end of file diff --git a/413/CH1/EX1.5/Example_2.sce b/413/CH1/EX1.5/Example_2.sce new file mode 100644 index 000000000..978f18a2f --- /dev/null +++ b/413/CH1/EX1.5/Example_2.sce @@ -0,0 +1,33 @@ +// Using Muller's method finding root of f(x)=3*x+sin(x)-exp(x), starting from 0 , 0.5 and 1
+clearglobal()
+clc;
+fx='3*x+sin(x)-exp(x)'
+x0=0.5; x1=1.0; x2=0; fr=2;
+tol=0.0000001
+i=1;
+while abs(fr)>tol
+x = x0; f0=eval(fx);
+x = x1; f1=eval(fx);
+x = x2; f2=eval(fx);
+h1=x1-x0; h2=x0-x2; h3=h2/h1;
+c=f0;
+a=(h3*f1-f0*(1+h3)+f2)/(h3*h1.^2 *(1+h3))
+b=(f1-f0-a*h1.^2)/h1
+if b>=0 then
+ root=x0-2*c/(b+sqrtm(b*b-4*a*c))
+else root=x0-2*c/(b-sqrtm(b*b-4*a*c))
+end
+x = root; fr=eval(fx);
+if root>x0 then
+ x1=x0;
+ x2=x1;
+ x0=root;
+
+else
+ x1=root;
+
+end
+X=[i,a,b,c,root]
+disp(X)
+i=i+1;
+end
\ No newline at end of file diff --git a/413/CH2/EX2.1/Example_2_1.sce b/413/CH2/EX2.1/Example_2_1.sce new file mode 100644 index 000000000..33637531c --- /dev/null +++ b/413/CH2/EX2.1/Example_2_1.sce @@ -0,0 +1,16 @@ +//Matrix operations
+clearglobal()
+clc;
+A=[3 -1 4;0 2 -3; 1 1 2]
+printf('Matrix is')
+disp(A)
+printf('Transpose is')
+ disp (A')
+ printf('Trace of Matrix is')
+ disp(trace(A))
+ printf('Determinant of Matrix is')
+ disp(det(A))
+printf('Characteristic equation of Matrix is')
+disp(poly(A,"x"))
+printf('Eigenvalues of Matrix is')
+ disp(spec(A))
\ No newline at end of file diff --git a/413/CH2/EX2.2/Example_2_2.sce b/413/CH2/EX2.2/Example_2_2.sce new file mode 100644 index 000000000..81e791613 --- /dev/null +++ b/413/CH2/EX2.2/Example_2_2.sce @@ -0,0 +1,8 @@ +//Inverse of A Matrix
+clearglobal()
+clc;
+A=[1 -1 2;3 0 1;1 0 2]
+printf('Matrix is')
+disp(A)
+printf('Inverse is')
+ disp (inv(A))
\ No newline at end of file diff --git a/413/CH2/EX2.3/Example_2_3.sce b/413/CH2/EX2.3/Example_2_3.sce new file mode 100644 index 000000000..b3d1a7503 --- /dev/null +++ b/413/CH2/EX2.3/Example_2_3.sce @@ -0,0 +1,12 @@ +// Compute 1-, 2-, inf norms of the vector x, if x=[1.25, 0.02, -5.15, 0]
+clearglobal()
+clc;
+x=[1.25 0.02 -5.15 0]
+printf('x is')
+disp(x)
+printf('First Norm of x is')
+disp(norm(x,1))
+printf('Second Norm of x is')
+disp(norm(x,2))
+printf('infinite Norm of x is')
+disp(norm(x,'inf'))
\ No newline at end of file diff --git a/413/CH2/EX2.4/Example_2_4.sce b/413/CH2/EX2.4/Example_2_4.sce new file mode 100644 index 000000000..c307d1cf2 --- /dev/null +++ b/413/CH2/EX2.4/Example_2_4.sce @@ -0,0 +1,24 @@ + //Compute the Frobenius norms of A, B, C and the infinity norms
+clearglobal()
+clc;
+A=[5 9;-2 1]
+printf('Matrix A is')
+disp(A)
+printf('Frobenius Norm of A is')
+disp(norm(A,'fro'))
+B=[0.1 0;0.2 0.1]
+printf('infinite Norm of A is')
+disp(norm(A,'inf'))
+printf('Matrix B is')
+disp(B)
+printf('Frobenius Norm of B is')
+disp(norm(B,'fro'))
+printf('infinite Norm of B is')
+disp(norm(B,'inf'))
+C=[0.2 0.1;0.1 0]
+printf('Matrix C is')
+disp(C)
+printf('Frobenius Norm of C is')
+disp(norm(C,'fro'))
+printf('infinite Norm of C is')
+disp(norm(C,'inf'))
\ No newline at end of file diff --git a/413/CH2/EX2.5/LU_Decomposition.sce b/413/CH2/EX2.5/LU_Decomposition.sce new file mode 100644 index 000000000..11afb1bc6 --- /dev/null +++ b/413/CH2/EX2.5/LU_Decomposition.sce @@ -0,0 +1,13 @@ +//LU Decomposition
+clearglobal()
+clc;
+A=[0 2 0 1 0; 2 2 3 2 -2; 4 -3 0 1 -7; 6 1 -6 -5 6]
+[L, U, P]=lu(A)
+printf('Matrix is')
+disp(A)
+printf('L=')
+disp(L)
+printf('U=')
+disp(U)
+printf('P=')
+disp(P)
\ No newline at end of file diff --git a/413/CH3/EX3.1/Example_3_1.sce b/413/CH3/EX3.1/Example_3_1.sce new file mode 100644 index 000000000..6b6b409ab --- /dev/null +++ b/413/CH3/EX3.1/Example_3_1.sce @@ -0,0 +1,17 @@ +clc
+clear
+x=[3.2 2.7 1 4.8 5.6]
+y=[22 17.8 14.2 38.3 51.7]
+for i=1:1:5
+X=[x(1,i) y(1,i)]
+disp(X)
+end
+
+P31=(3-x(1,2))*(3-x(1,3))*(3-x(1,4))*(3-x(1,5))*y(1,1)/((x(1,1)-x(1,2))*(x(1,1)-x(1,3))*(x(1,1)-x(1,4))*(x(1,1)-x(1,5)));
+P32=(3-x(1,1))*(3-x(1,3))*(3-x(1,4))*(3-x(1,5))*y(1,2)/((x(1,2)-x(1,1))*(x(1,2)-x(1,3))*(x(1,2)-x(1,4))*(x(1,2)-x(1,5)))
+P33=(3-x(1,2))*(3-x(1,1))*(3-x(1,4))*(3-x(1,5))*y(1,3)/((x(1,3)-x(1,2))*(x(1,3)-x(1,1))*(x(1,3)-x(1,4))*(x(1,3)-x(1,5)))
+P34=(3-x(1,2))*(3-x(1,3))*(3-x(1,1))*(3-x(1,5))*y(1,4)/((x(1,4)-x(1,2))*(x(1,4)-x(1,3))*(x(1,4)-x(1,1))*(x(1,4)-x(1,5)))
+P35=(3-x(1,2))*(3-x(1,3))*(3-x(1,4))*(3-x(1,1))*y(1,5)/((x(1,5)-x(1,2))*(x(1,5)-x(1,3))*(x(1,5)-x(1,4))*(x(1,5)-x(1,1)))
+printf(' Ploynomial at x=3 is')
+P=P31+P32+P33+P34+P35
+disp(P)
\ No newline at end of file diff --git a/413/CH3/EX3.2/Example_3_2.sce b/413/CH3/EX3.2/Example_3_2.sce new file mode 100644 index 000000000..b28cfce2d --- /dev/null +++ b/413/CH3/EX3.2/Example_3_2.sce @@ -0,0 +1,29 @@ +clc
+clear
+x=[32 22.2 41.6 10.1 50.5]
+y=[0.52992 0.37784 0.66393 0.17537 0.63608]
+for i=1:1:5
+X=[x(1,i) y(1,i)]
+disp(X)
+end
+a=27.5
+for i=1:4
+ A(1,i)=((a-x(1,i))*y(1,i+1)+(x(1,i+1)-a)*y(1,i))/(x(1,i+1)-x(1,i))
+end
+for i=1:3
+ B(1,i)=((a-x(1,i))*A(1,i+1)+(x(1,i+2)-a)*A(1,i))/(x(1,i+2)-x(1,i))
+end
+for i=1:2
+ C(1,i)=((a-x(1,i))*B(1,i+1)+(x(1,i+3)-a)*B(1,i))/(x(1,i+3)-x(1,i))
+end
+D(1,1)=((a-x(1,1))*C(1,2)+(x(1,5)-a)*C(1,1))/(x(1,5)-x(1,1))
+out=[0,x(1,1),y(1,1) ]
+disp(out)
+out1=[1,x(1,2),y(1,2), A(1,1) ]
+disp(out1)
+out2=[2,x(1,3),y(1,3), A(1,2), B(1,1),C(1,1),D(1,1) ]
+disp(out2)
+out3=[3,x(1,4),y(1,4), A(1,3), B(1,2),C(1,2) ]
+disp(out3)
+out4=[4,x(1,5),y(1,5), A(1,4), B(1,3) ]
+disp(out4)
\ No newline at end of file diff --git a/413/CH3/EX3.3/Example_3_3.sce b/413/CH3/EX3.3/Example_3_3.sce new file mode 100644 index 000000000..efd167c30 --- /dev/null +++ b/413/CH3/EX3.3/Example_3_3.sce @@ -0,0 +1,32 @@ +clc
+clear
+x=[3.2 2.7 1 4.8 5.6];
+y=[22 17.8 14.2 38.3 51.7]
+for i=1:1:5
+X=[x(1,i) y(1,i)]
+disp(X)
+end
+for i=1:1:4
+A(1,i)=(y(1,i+1)-y(1,i))/(x(1,i+1)-x(1,i))
+end
+for i=1:1:3
+B(1,i)=(A(1,i+1)-A(1,i))/(x(1,i+2)-x(1,i))
+end
+for i=1:1:2
+C(1,i)=(B(1,i+1)-B(1,i))/(x(1,i+3)-x(1,i))
+end
+for i=1:1:1
+D(1,i)=(C(1,i+1)-C(1,i))/(x(1,i+4)-x(1,i))
+end
+out=[x(1,1),y(1,1) ]
+disp(out)
+out1=[x(1,2),y(1,2), A(1,1) ]
+disp(out1)
+out2=[x(1,3),y(1,3), A(1,2), B(1,1),C(1,1),D(1,1) ]
+disp(out2)
+out3=[x(1,4),y(1,4), A(1,3), B(1,2),C(1,2) ]
+disp(out3)
+out4=[x(1,5),y(1,5), A(1,4), B(1,3) ]
+disp(out4)
+P3=C(1,1)*(3-x(1,1))*(3-x(1,2))*(3-x(1,3))+B(1,1)*(3-x(1,1))*(3-x(1,2))+A(1,1)*(3-x(1,1))+y(1,1)
+disp(P3)
\ No newline at end of file diff --git a/413/CH3/EX3.4/Example_3_4.sce b/413/CH3/EX3.4/Example_3_4.sce new file mode 100644 index 000000000..40944d326 --- /dev/null +++ b/413/CH3/EX3.4/Example_3_4.sce @@ -0,0 +1,28 @@ +clc
+clear
+x=[1.10 2.00 3.50 5.00 7.10];
+for i=1:5
+y(1,i)=x(1,i).*x(1,i).*exp(-x(1,i)/2)
+end
+for i=1:1:4
+A(1,i)=(y(1,i+1)-y(1,i))/(x(1,i+1)-x(1,i))
+end
+for i=1:1:3
+B(1,i)=(A(1,i+1)-A(1,i))/(x(1,i+2)-x(1,i))
+end
+for i=1:1:2
+C(1,i)=(B(1,i+1)-B(1,i))/(x(1,i+3)-x(1,i))
+end
+for i=1:1:1
+D(1,i)=(C(1,i+1)-C(1,i))/(x(1,i+4)-x(1,i))
+end
+out=[x(1,1),y(1,1) ]
+disp(out)
+out1=[x(1,2),y(1,2), A(1,1) ]
+disp(out1)
+out2=[x(1,3),y(1,3), A(1,2), B(1,1),C(1,1),D(1,1) ]
+disp(out2)
+out3=[x(1,4),y(1,4), A(1,3), B(1,2),C(1,2) ]
+disp(out3)
+out4=[x(1,5),y(1,5), A(1,4), B(1,3) ]
+disp(out4)
\ No newline at end of file diff --git a/413/CH3/EX3.5/Table_3_2.sce b/413/CH3/EX3.5/Table_3_2.sce new file mode 100644 index 000000000..14ca10cf3 --- /dev/null +++ b/413/CH3/EX3.5/Table_3_2.sce @@ -0,0 +1,28 @@ +clc
+clear
+clc
+clear
+x=[3.2 2.7 1 4.8 5.6];
+y=[22 17.8 14.2 38.3 51.7]
+for i=1:1:4
+A(1,i)=(y(1,i+1)-y(1,i))/(x(1,i+1)-x(1,i))
+end
+for i=1:1:3
+B(1,i)=(A(1,i+1)-A(1,i))/(x(1,i+2)-x(1,i))
+end
+for i=1:1:2
+C(1,i)=(B(1,i+1)-B(1,i))/(x(1,i+3)-x(1,i))
+end
+for i=1:1:1
+D(1,i)=(C(1,i+1)-C(1,i))/(x(1,i+4)-x(1,i))
+end
+out=[x(1,1),y(1,1) ]
+disp(out)
+out1=[x(1,2),y(1,2), A(1,1) ]
+disp(out1)
+out2=[x(1,3),y(1,3), A(1,2), B(1,1),C(1,1),D(1,1) ]
+disp(out2)
+out3=[x(1,4),y(1,4), A(1,3), B(1,2),C(1,2) ]
+disp(out3)
+out4=[x(1,5),y(1,5), A(1,4), B(1,3) ]
+disp(out4)
\ No newline at end of file diff --git a/413/CH3/EX3.6/Table_3_5a.sce b/413/CH3/EX3.6/Table_3_5a.sce new file mode 100644 index 000000000..3ebdbc077 --- /dev/null +++ b/413/CH3/EX3.6/Table_3_5a.sce @@ -0,0 +1,32 @@ +clc
+clear
+x=[0 0.5 1 1.5 2 2.5 3]
+for i=1:7
+y(1,i)=2*x(1,i).*x(1,i).*x(1,i)
+end
+for i=1:1:6
+A(1,i)=(y(1,i+1)-y(1,i))
+end
+for i=1:1:5
+B(1,i)=(A(1,i+1)-A(1,i))
+end
+for i=1:1:4
+C(1,i)=(B(1,i+1)-B(1,i))
+end
+for i=1:1:3
+D(1,i)=(C(1,i+1)-C(1,i))
+end
+out=[x(1,1),y(1,1) ]
+disp(out)
+out1=[x(1,2),y(1,2), A(1,1) ]
+disp(out1)
+out2=[x(1,3),y(1,3), A(1,2), B(1,1),C(1,1),D(1,1) ]
+disp(out2)
+out3=[x(1,4),y(1,4), A(1,3), B(1,2),C(1,2) ]
+disp(out3)
+out4=[x(1,5),y(1,5), A(1,4), B(1,3), C(1,3) ]
+disp(out4)
+out5=[x(1,6),y(1,6), A(1,5), B(1,4) , C(1,4)]
+disp(out5)
+out6=[x(1,7),y(1,7), A(1,6), B(1,5) ]
+disp(out6)
diff --git a/413/CH3/EX3.7/Table_3_5b.sce b/413/CH3/EX3.7/Table_3_5b.sce new file mode 100644 index 000000000..615550cc1 --- /dev/null +++ b/413/CH3/EX3.7/Table_3_5b.sce @@ -0,0 +1,32 @@ +clc
+clear
+x=[0 0.5 1 1.5 2 2.5 3]
+for i=1:7
+y(1,i)=2*x(1,i).*x(1,i).*x(1,i)
+end
+for i=1:1:6
+A(1,i)=(y(1,i+1)-y(1,i))/(x(1,i+1)-x(1,i))
+end
+for i=1:1:5
+B(1,i)=(A(1,i+1)-A(1,i))/(x(1,i+2)-x(1,i))
+end
+for i=1:1:4
+C(1,i)=(B(1,i+1)-B(1,i))/(x(1,i+3)-x(1,i))
+end
+for i=1:1:3
+D(1,i)=(C(1,i+1)-C(1,i))/(x(1,i+4)-x(1,i))
+end
+out=[x(1,1),y(1,1) ]
+disp(out)
+out1=[x(1,2),y(1,2), A(1,1) ]
+disp(out1)
+out2=[x(1,3),y(1,3), A(1,2), B(1,1),C(1,1),D(1,1) ]
+disp(out2)
+out3=[x(1,4),y(1,4), A(1,3), B(1,2),C(1,2) ]
+disp(out3)
+out4=[x(1,5),y(1,5), A(1,4), B(1,3), C(1,3) ]
+disp(out4)
+out5=[x(1,6),y(1,6), A(1,5), B(1,4) , C(1,4)]
+disp(out5)
+out6=[x(1,7),y(1,7), A(1,6), B(1,5) ]
+disp(out6)
diff --git a/413/CH4/EX4.1/Table_4_1.sce b/413/CH4/EX4.1/Table_4_1.sce new file mode 100644 index 000000000..709546706 --- /dev/null +++ b/413/CH4/EX4.1/Table_4_1.sce @@ -0,0 +1,25 @@ +clc
+clear
+
+function a=eco4(x)
+ a=1.000043+x+x.*x.*0.499219+x.*x.*x/6+x.*x.*x.*x.*0.043750
+endfunction
+function a=eco5(x)
+ a=1.000043+x+x.*x.*0.499219+x.*x.*x/6+x.*x.*x.*x.*0.043750+x.*x.*x.*x.*x/120
+endfunction
+function a=mac4(x)
+ a=1+x+x.*x/2+x.*x.*x/6+x.*x.*x.*x/24
+endfunction
+function a=mac5(x)
+ a=1+x+x.*x/2+x.*x.*x/6+x.*x.*x.*x/24+x.*x.*x.*x.*x/120
+endfunction
+function a=mac6(x)
+ a=1+x+x.*x/2+x.*x.*x/6+x.*x.*x.*x/24+x.*x.*x.*x.*x/120+x.*x.*x.*x.*x.*x/720
+endfunction
+function out=tab4(y)
+out=[y,exp(y),mac6(y),mac5(y),mac4(y),eco5(y),eco4(y)]
+
+endfunction
+for y=0:0.2:1
+disp(tab4(y))
+end
\ No newline at end of file diff --git a/413/CH4/EX4.2/Table_4_2.sce b/413/CH4/EX4.2/Table_4_2.sce new file mode 100644 index 000000000..4a76be593 --- /dev/null +++ b/413/CH4/EX4.2/Table_4_2.sce @@ -0,0 +1,16 @@ +clc
+clear
+
+function a=che(x)
+ a=0.9946+0.9973.*x+x.*x.*0.543+x.*x.*x.*0.1772
+ endfunction
+function a=mac(x)
+ a=1+x+x.*x/2+x.*x.*x/6
+endfunction
+function out=tab(y)
+out=[y,exp(y),che(y),exp(y)-che(y),mac(y),exp(y)-mac(y)]
+
+endfunction
+for y=-1:0.2:1
+disp(tab(y))
+end
\ No newline at end of file diff --git a/413/CH4/EX4.4/Table_4_4.sce b/413/CH4/EX4.4/Table_4_4.sce new file mode 100644 index 000000000..d261a1ed8 --- /dev/null +++ b/413/CH4/EX4.4/Table_4_4.sce @@ -0,0 +1,14 @@ +clc
+clear
+function a=pade(x)
+ a=(x+7*x.*x.*x/9 +64*x.*x.*x.*x.*x/945)/(1+10*x.*x/9 +5*x.*x.*x.*x/21)
+endfunction
+function a=mac(x)
+ a=x-x.*x.*x/3+x.*x.*x.*x.*x/5-x.*x.*x.*x.*x.*x.*x/7+x.*x.*x.*x.*x.*x.*x.*x.*x/9
+endfunction
+function out=tab4(y)
+out=[y,atan(y),pade(y),atan(y)-pade(y),mac(y),atan(y)-mac(y)]
+endfunction
+for y=0.2:0.2:1
+disp(tab4(y))
+end
\ No newline at end of file diff --git a/413/CH4/EX4.5/Table_4_5.sce b/413/CH4/EX4.5/Table_4_5.sce new file mode 100644 index 000000000..e38fbfbc0 --- /dev/null +++ b/413/CH4/EX4.5/Table_4_5.sce @@ -0,0 +1,14 @@ +clc
+clear
+function a=rat(x)
+ a=(1.0018+0.6727*x +0.1598*x.*x)/(1-0.3263*x)
+endfunction
+function a=che(x)
+ a=0.9946+0.9973.*x+x.*x.*0.543+x.*x.*x.*0.1772
+ endfunction
+function out=tab4(y)
+out=[y,exp(y),che(y),exp(y)-che(y), rat(y),exp(y)-rat(y)]
+endfunction
+for y=-1:0.2:1
+disp(tab4(y)')
+end
\ No newline at end of file diff --git a/413/CH5/EX5.1/Example_5_1.sce b/413/CH5/EX5.1/Example_5_1.sce new file mode 100644 index 000000000..1756bc344 --- /dev/null +++ b/413/CH5/EX5.1/Example_5_1.sce @@ -0,0 +1,11 @@ +clc
+clear
+x=[1.6 1.8 2 2.2 2.4 2.6 2.8 3 3.2 3.4 3.6 3.8];
+F=[4.953 6.05 7.389 9.025 11.023 13.464 16.445 20.086 24.533 29.964 36.594 44.701]
+for i=1:12
+X=[x(1,i), F(1,i)]
+disp(X)
+end
+A=(0.2/2)*[(6.05+29.964)+2*(7.389+9.025+11.023+13.464+16.445+20.086+24.533)]
+printf('Answer by Trapezoidal Rule to estimate the integral from x=1.8 to x=3.4')
+disp(A)
\ No newline at end of file diff --git a/413/CH5/EX5.2/Example_5_2.sce b/413/CH5/EX5.2/Example_5_2.sce new file mode 100644 index 000000000..44202a68e --- /dev/null +++ b/413/CH5/EX5.2/Example_5_2.sce @@ -0,0 +1,56 @@ +clc
+clear
+sumR2=0
+sumR3=0
+sumR4=0
+function a=fun(x)
+ a=exp(-x.*x)
+endfunction
+A=[0.2 1.5]
+M=(A(1,1)+A(1,2))/2
+
+h=M-0.2
+R1=(h)/2 *[fun(0.2)+fun(1.5)+2*fun(M)]
+
+h1=h/2
+for i=1:3
+ B(1,i)=0.2+i*h1
+ sumR2=fun(B(1,i))+sumR2
+ end
+R2=h1/2 *[fun(0.2)+fun(1.5)+2*sumR2]
+
+h2=h1/2
+for i=1:7
+ C(1,i)=0.2+i*h2
+ sumR3=fun(C(1,i))+sumR3
+ end
+R3=h2/2 *[fun(0.2)+fun(1.5)+2*sumR3]
+
+h3=h2/2
+for i=1:15
+ D(1,i)=0.2+i*h3
+ sumR4=fun(D(1,i))+sumR4
+ end
+R4=h3/2 *[fun(0.2)+fun(1.5)+2*sumR4]
+
+
+R5=R2+1/3*(R2-R1)
+
+R6=R3+1/3*(R3-R2)
+
+R7=R4+1/3*(R4-R3)
+
+R8=R6+1/3*(R6-R5)
+
+R9=R7+1/3*(R7-R6)
+
+R10=R9+1/3*(R9-R8)
+
+T1=[R1]
+T2=[R2, R5]
+T3=[R3, R6, R8]
+T4=[R4,R7,R9,R10]
+disp(T1)
+disp(T2)
+disp(T3)
+disp(T4)
diff --git a/413/CH5/EX5.3/Example_5_3.sce b/413/CH5/EX5.3/Example_5_3.sce new file mode 100644 index 000000000..c6a9bc6ad --- /dev/null +++ b/413/CH5/EX5.3/Example_5_3.sce @@ -0,0 +1,25 @@ +clc
+clear
+x=[1.6 1.8 2 2.2 2.4 2.6 2.8 3 3.2 3.4 3.6 3.8];
+F=[4.953 6.05 7.389 9.025 11.023 13.464 16.445 20.086 24.533 29.964 36.594 44.701]
+for i=1:12
+X=[x(1,i), F(1,i)]
+end
+A1=(0.2/2)*[(6.05+29.964)+2*(7.389+9.025+11.023+13.464+16.445+20.086+24.533)]
+printf('Answer by Trapezoidal Rule to estimate the integral from x=1.8 to x=3.4 taking h=0.2')
+disp(A1)
+A2=(0.4/2)*[(6.05+29.964)+2*(9.025+13.464+20.086)]
+printf('Answer by Trapezoidal Rule to estimate the integral from x=1.8 to x=3.4 taking h =0.4')
+disp(A2)
+A3=(0.8/2)*[(6.05+29.964)+2*(13.464)]
+printf('Answer by Trapezoidal Rule to estimate the integral from x=1.8 to x=3.4 taking h=0.8')
+disp(A3)
+A4=A1+(A1-A2)/3
+A5=A2+(A2-A3)/3
+A6=A4+(A4-A5)/3
+T1=[0.2 A1 A4 A6]
+T2=[0.4 A2 A5]
+T3=[0.8 A3]
+disp(T1)
+disp(T2)
+disp(T3)
\ No newline at end of file diff --git a/413/CH5/EX5.4/Example_5_4.sce b/413/CH5/EX5.4/Example_5_4.sce new file mode 100644 index 000000000..bbe9a229c --- /dev/null +++ b/413/CH5/EX5.4/Example_5_4.sce @@ -0,0 +1,69 @@ +clc
+clear
+a=0.2
+b=2.6
+function p=f(c)
+ p=exp(-c.^2)
+endfunction
+
+for n=6:6:24
+a=0.2
+ST=0
+h=(b-a)/n
+for i=1:n+1
+ T=[a,f(a)]
+ A(1,i)=a
+ a=a+h
+end
+for i=2:n
+ ST=ST+2*f(A(1,i))
+end
+TZ(1,n)=(h/2)*(f(0.2)+f(2.6)+ST)
+end
+for n=6:6:24
+a=0.2
+ST1=0
+ST2=0
+h=(b-a)/n
+for i=1:n+1
+ A(1,i)=a
+ a=a+h
+
+end
+
+for i=2:2:n-2
+ ST1=ST1+2*f(A(1,i+1))
+ ST2=ST2+4*f(A(1,i))
+end
+ ST2=ST2+4*f(A(1,n))
+
+TS3(1,n)=(h/3)*(f(0.2)+f(2.6)+ST1+ST2)
+
+end
+for n=6:6:24
+a=0.2
+ST1=0
+ST2=0
+ST3=0
+h=(b-a)/n
+for i=1:n+1
+ A(1,i)=a
+ a=a+h
+end
+for i=2:3:n-3
+ ST1=ST1+3*f(A(1,i))
+ ST2=ST2+3*f(A(1,i+1))
+ ST3=ST3+2*f(A(1,i+2))
+end
+ ST2=ST2+3*f(A(1,n))
+ ST1=ST1+3*f(A(1,n-1))
+
+TS38(1,n)=(h*3/8)*(f(0.2)+f(2.6)+ST1+ST2+ST3)
+end
+for i=1:4
+ n=i*6
+ R=[n, TZ(1,n), 0.6886527145-TZ(1,n),TS3(1,n),0.6886527145-TS3(1,n),TS38(1,n),0.6886527145-TS38(1,n)]
+ disp(R)
+end
+
+
diff --git a/413/CH5/EX5.5/Example_5_5.sce b/413/CH5/EX5.5/Example_5_5.sce new file mode 100644 index 000000000..15d85a86b --- /dev/null +++ b/413/CH5/EX5.5/Example_5_5.sce @@ -0,0 +1,62 @@ +clc
+clear
+a=0
+b=2
+function p=fA(c,n)
+ p=c*cos((n*c*%pi)/2)
+endfunction
+function q=fB(c,n)
+ q=c*sin((n*c*%pi)/2)
+endfunction
+for n=1:5
+for t=20:180:200
+a=0
+ST=0
+ST1=0
+h=(b-a)/t
+for i=1:t+1
+ A(1,i)=a
+ a=a+h
+end
+for i=2:t
+ ST=ST+2*fA(A(1,i),n)
+ ST1=ST1+2*fB(A(1,i),n)
+end
+TZA(t,n)=(h/2)*(fA((0),n)+fA((2),n)+ST)
+TZB(t,n)=(h/2)*(fB((0),n)+fB((2),n)+ST1)
+end
+end
+for t=20:180:200
+
+for n=1:5
+a=0
+ST1=0
+ST2=0
+ST3=0
+ST4=0
+h=(b-a)/t
+for i=1:t+1
+ A(1,i)=a
+ a=a+h
+end
+for i=2:2:t-2
+ ST1=ST1+2*fA(A(1,i+1),n)
+ ST2=ST2+4*fA(A(1,i),n)
+ ST3=ST3+2*fB(A(1,i+1),n)
+ ST4=ST4+4*fB(A(1,i),n)
+end
+ ST2=ST2+4*fA(A(1,t),n)
+ ST4=ST4+4*fB(A(1,t),n)
+TSA3(t,n)=(h/3)*(fA(0,n)+fA(2,n)+ST1+ST2)
+
+TSB3(t,n)=(h/3)*(fB(0,n)+fB(2,n)+ST3+ST4)
+
+end
+end
+for t=20:180:200
+ printf('Comparison of numerical integration of %f subdivisions of [0 2]',t)
+for n=1:5
+ T=[n,TZA(t,n),TZB(t,n),TSA3(t,n),TSB3(t,n)]
+ disp(T)
+end
+end
diff --git a/413/CH5/EX5.6/Table_5_1.sce b/413/CH5/EX5.6/Table_5_1.sce new file mode 100644 index 000000000..33d26119e --- /dev/null +++ b/413/CH5/EX5.6/Table_5_1.sce @@ -0,0 +1,14 @@ +clc
+clear
+x=1.9;
+function a=expsin(y)
+ a=(exp(x+y).*sin(x+y)-exp(x).*sin(x))/y
+endfunction
+function out=tab5(y)
+out=[y,expsin(y)]
+endfunction
+y=0.05
+for i=0:1:10
+disp(tab5(y))
+y=y.*0.5
+end
\ No newline at end of file diff --git a/413/CH5/EX5.7/Table_5_2.sce b/413/CH5/EX5.7/Table_5_2.sce new file mode 100644 index 000000000..159debee2 --- /dev/null +++ b/413/CH5/EX5.7/Table_5_2.sce @@ -0,0 +1,14 @@ +clc
+clear
+x=1.9;
+function a=expsin(y)
+ a=(exp(x+y).*sin(x+y)-exp(x-y).*sin(x-y))/(2*y)
+endfunction
+function out=tab5(y)
+out=[y,expsin(y)]
+endfunction
+y=0.05
+for i=0:1:6
+disp(tab5(y))
+y=y.*0.5
+end
\ No newline at end of file diff --git a/413/CH5/EX5.8/Table_5_3.sce b/413/CH5/EX5.8/Table_5_3.sce new file mode 100644 index 000000000..5964235bf --- /dev/null +++ b/413/CH5/EX5.8/Table_5_3.sce @@ -0,0 +1,42 @@ +clc
+clear
+clc
+clear
+x=[1.7 1.8 2 2.35 2.50];
+function a=expsin(x)
+ a=exp(x).*sin(x)
+endfunction
+for i=1:1:4
+function b=firstdivdiff(x)
+b=(expsin(x(1,i+1))-expsin(x(1,i)))/(x(1,i+1)-x(1,i))
+endfunction
+A(1,i)=firstdivdiff(x)
+end
+for i=1:1:3
+function b=Secdivdiff(x)
+b=(A(1,i+1)-A(1,i))/(x(1,i+2)-x(1,i))
+endfunction
+B(1,i)=Secdivdiff(x)
+end
+for i=1:1:2
+function b=thdivdiff(x)
+b=(B(1,i+1)-B(1,i))/(x(1,i+3)-x(1,i))
+endfunction
+C(1,i)=thdivdiff(x)
+end
+for i=1:1:1
+function b=fodivdiff(x)
+b=(C(1,i+1)-C(1,i))/(x(1,i+4)-x(1,i))
+endfunction
+D(1,i)=fodivdiff(x)
+end
+out=[0,x(1,1),expsin(x(1,1)) ]
+disp(out)
+out1=[1,x(1,2),expsin(x(1,2)), A(1,1) ]
+disp(out1)
+out2=[2,x(1,3),expsin(x(1,3)), A(1,2), B(1,1) ]
+disp(out2)
+out3=[3,x(1,4),expsin(x(1,4)), A(1,3), B(1,2),C(1,1),D(1,1) ]
+disp(out3)
+out4=[4,x(1,5),expsin(x(1,5)), A(1,4), B(1,3),C(1,2) ]
+disp(out4)
\ No newline at end of file diff --git a/413/CH5/EX5.9/Table_5_4.sce b/413/CH5/EX5.9/Table_5_4.sce new file mode 100644 index 000000000..c5e16db7f --- /dev/null +++ b/413/CH5/EX5.9/Table_5_4.sce @@ -0,0 +1,40 @@ +clc
+clear
+x=[1.7 1.9 2.1 2.3 2.50];
+function a=expsin(x)
+ a=exp(x).*sin(x)
+endfunction
+for i=1:1:4
+function b=firstdivdiff(x)
+b=(expsin(x(1,i+1))-expsin(x(1,i)))
+endfunction
+A(1,i)=firstdivdiff(x)
+end
+for i=1:1:3
+function b=Secdivdiff(x)
+b=(A(1,i+1)-A(1,i))
+endfunction
+B(1,i)=Secdivdiff(x)
+end
+for i=1:1:2
+function b=thdivdiff(x)
+b=(B(1,i+1)-B(1,i))
+endfunction
+C(1,i)=thdivdiff(x)
+end
+for i=1:1:1
+function b=fodivdiff(x)
+b=(C(1,i+1)-C(1,i))
+endfunction
+D(1,i)=fodivdiff(x)
+end
+out=[0,x(1,1),expsin(x(1,1)) ]
+disp(out)
+out1=[1,x(1,2),expsin(x(1,2)), A(1,1) ]
+disp(out1)
+out2=[2,x(1,3),expsin(x(1,3)), A(1,2), B(1,1) ]
+disp(out2)
+out3=[3,x(1,4),expsin(x(1,4)), A(1,3), B(1,2),C(1,1),D(1,1) ]
+disp(out3)
+out4=[4,x(1,5),expsin(x(1,5)), A(1,4), B(1,3),C(1,2) ]
+disp(out4)
\ No newline at end of file diff --git a/413/CH6/EX6.1/Example_6_1.sce b/413/CH6/EX6.1/Example_6_1.sce new file mode 100644 index 000000000..53ac5b27b --- /dev/null +++ b/413/CH6/EX6.1/Example_6_1.sce @@ -0,0 +1,44 @@ +clc
+clear
+x=[0 0.2 0.4 0.6 0.8]
+h=0.2
+y(1,1)=-1
+for i=1:4
+ k1(1,i)=h*(-2*x(1,i)-y(1,i))
+ k2(1,i)=h*(-2*(x(1,i)+h/4)-(y(1,i)+k1(1,i)/4))
+ k3(1,i)=h*(-2*(x(1,i)+(3*h)/8)-(y(1,i)+(3*k1(1,i))/32+(9*k2(1,i))/32))
+ k4(1,i)=h*(-2*(x(1,i)+(12*h)/13)-(y(1,i)+(1932*k1(1,i))/2197-(7200*k2(1,i))/2197+(7296*k3(1,i))/2197))
+ k5(1,i)=h*(-2*(x(1,i)+(h))-(y(1,i)+(439*k1(1,i))/216-(8*k2(1,i))+(3680*k3(1,i))/513-(845*k4(1,i)/4104)))
+ k6(1,i)=h*(-2*(x(1,i)+(h/2))-(y(1,i)-(8*k1(1,i))/27+(2*k2(1,i))-(3544*k3(1,i))/2565+(1859*k4(1,i)/4104)-11*k5(1,i)/40))
+ kA(1,i)=(16*k1(1,i)/135+6656*k3(1,i)/12825+28561*k4(1,i)/56430-9*k5(1,i)/50+2*k6(1,i)/55)
+ y(1,i+1)=y(1,i)+kA(1,i)
+ B(1,i)=-3.*exp(-x(1,i))-2*x(1,i)+2
+ C(1,i)=-2*x(1,i)-y(1,i)
+end
+for i=1:3
+T=[x(1,i), y(1,i),B(1,i) ,C(1,i)]
+disp(T)
+end
+P=y(1,3)+(h/12)*(23*C(1,3)-16*C(1,2)+5*C(1,1))
+printf('Value at y(0.6) is %f',P)
+x=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8]
+h=0.1
+y(1,1)=-1
+for i=1:7
+ k1(1,i)=h*(-2*x(1,i)-y(1,i))
+ k2(1,i)=h*(-2*(x(1,i)+h/4)-(y(1,i)+k1(1,i)/4))
+ k3(1,i)=h*(-2*(x(1,i)+(3*h)/8)-(y(1,i)+(3*k1(1,i))/32+(9*k2(1,i))/32))
+ k4(1,i)=h*(-2*(x(1,i)+(12*h)/13)-(y(1,i)+(1932*k1(1,i))/2197-(7200*k2(1,i))/2197+(7296*k3(1,i))/2197))
+ k5(1,i)=h*(-2*(x(1,i)+(h))-(y(1,i)+(439*k1(1,i))/216-(8*k2(1,i))+(3680*k3(1,i))/513-(845*k4(1,i)/4104)))
+ k6(1,i)=h*(-2*(x(1,i)+(h/2))-(y(1,i)-(8*k1(1,i))/27+(2*k2(1,i))-(3544*k3(1,i))/2565+(1859*k4(1,i)/4104)-11*k5(1,i)/40))
+ kA(1,i)=(16*k1(1,i)/135+6656*k3(1,i)/12825+28561*k4(1,i)/56430-9*k5(1,i)/50+2*k6(1,i)/55)
+ y(1,i+1)=y(1,i)+kA(1,i)
+ B(1,i)=-3.*exp(-x(1,i))-2*x(1,i)+2
+ C(1,i)=-2*x(1,i)-y(1,i)
+end
+for i=1:6
+T=[x(1,i), y(1,i),B(1,i) ,C(1,i)]
+disp(T)
+end
+R=y(1,6)+(h/12)*(23*C(1,6)-16*C(1,5)+5*C(1,4))
+printf('Value at y(0.6) is %f',)
diff --git a/413/CH6/EX6.10/Example_6_11.sce b/413/CH6/EX6.10/Example_6_11.sce new file mode 100644 index 000000000..e8f7ba367 --- /dev/null +++ b/413/CH6/EX6.10/Example_6_11.sce @@ -0,0 +1,23 @@ +A=[3,-1,0;-2,4,-3;0,-1,1;]
+disp(A)
+printf('Eigen values are:')
+disp(spec(A))
+printf('Display of Power Method:')
+U=[1,1,1]'
+for i=1:14
+ B=A*U
+ a=abs(B(1,1))
+ b=abs(B(2,1))
+ c=abs(B(3,1))
+ if ((a>b)&(a>c)) then
+ T= (B(1,1))
+ elseif ((b>a)&(b>c)) then
+ T=(B(2,1))
+ else T=(B(3,1))
+ end
+ printf('After %d iteration eigenvalue is ',i)
+ disp(T)
+ printf(' corresponding eigenvector is ')
+ U=B/T
+ disp(U)
+end
\ No newline at end of file diff --git a/413/CH6/EX6.11/Example_6_12.sce b/413/CH6/EX6.11/Example_6_12.sce new file mode 100644 index 000000000..881c7e02d --- /dev/null +++ b/413/CH6/EX6.11/Example_6_12.sce @@ -0,0 +1,35 @@ +A=[4,-1,1;1,1,1;-2,0,-6;]
+disp(A)
+printf('Eigen values are:')
+disp(spec(A))
+printf('Display of Shifting in Power Method:')
+printf('Shifted Matrix (Shifted by -6)is')
+A1=A-(-6)*eye(3,3)
+disp(A1)
+printf('Inverse of Shifted Matrix is' )
+A=inv(A1)
+disp(A)
+U=[1,1,1]'
+for i=1:4
+ B=A*U
+ a=abs(B(1,1))
+ b=abs(B(2,1))
+ c=abs(B(3,1))
+ if ((a>b)&(a>c)) then
+ T= (B(1,1))
+ elseif ((b>a)&(b>c)) then
+ T=(B(2,1))
+ else T=(B(3,1))
+ end
+ printf('After %d iteration eigenvalue of Inverse Shifted Matrix is ',i)
+ disp(T)
+ printf(' corresponding eigenvector of Inverse Shifted Matrix is ')
+ U=B/T
+ disp(U)
+end
+T1=1/T
+T2=-6+T1
+printf('Largest eigen value of Shifted Matrix' )
+disp(T1)
+printf('Largest eigen value of Matrix is' )
+disp(T2)
\ No newline at end of file diff --git a/413/CH6/EX6.12/Example_6_13.sce b/413/CH6/EX6.12/Example_6_13.sce new file mode 100644 index 000000000..c339fdf05 --- /dev/null +++ b/413/CH6/EX6.12/Example_6_13.sce @@ -0,0 +1,20 @@ +//Given This Matrix A, create a zero in position (4,2) by multiplying bu the proper @ Matrix)
+A=[7,8,6,6;1,6,-1,-2;,1,-2,5,-2;3,4,3,4;]
+printf('Matrix A is')
+disp(A)
+printf('Values of d, c,s are')
+d=sqrt(A(2,2)^2+A(4,2)^2)
+disp(d)
+c=A(2,2)/d
+disp(c)
+s=A(4,2)/d
+disp(s)
+printf('Matrix Q is')
+Q=[1,0,0,0;0,c,0,s;0,0,1,0;0,-s,0,c]
+disp(Q)
+printf('Matrix Q*A is')
+C=Q*A
+disp(C)
+printf('Matrix (Q*A*invsre(Q)) is')
+B=Q*A*Q'
+disp(B)
diff --git a/413/CH6/EX6.13/Example_6_14.sce b/413/CH6/EX6.13/Example_6_14.sce new file mode 100644 index 000000000..6fd447386 --- /dev/null +++ b/413/CH6/EX6.13/Example_6_14.sce @@ -0,0 +1,20 @@ +//Convert the Matrix A to upper Hessenberg
+A=[7,8,6,6;1,6,-1,-2;,1,-2,5,-2;3,4,3,4;]
+printf('Matrix A is')
+disp(A)
+printf('We can create zeros inthe first column and row 3 and 4 by B*A*B(invrse) Where B is')
+b3=A(3,1)/A(2,1)
+b4=A(4,1)/A(2,1)
+B=[1,0,0,0;0,1,0,0;0,-b3,1,0;0,-b4,0,1]
+disp(B)
+A=B*A*inv(B)
+printf('After perfroming the multiplication we have' )
+disp(A)
+printf('We can create zeros inthe second column and row 4 by B*A*B(invrse) Where B is')
+b4=A(4,2)/A(3,2)
+B=[1,0,0,0;0,1,0,0;0,0,1,0;0,0,-b4,1]
+disp(B)
+A=B*A*inv(B)
+printf('After perfroming the multiplication we have' )
+disp(A)
+printf('this is upper Hessenberg')
\ No newline at end of file diff --git a/413/CH6/EX6.2/Table_6_1.sce b/413/CH6/EX6.2/Table_6_1.sce new file mode 100644 index 000000000..d018aece6 --- /dev/null +++ b/413/CH6/EX6.2/Table_6_1.sce @@ -0,0 +1,11 @@ +clc
+clear
+x=[0 0.1 0.2 0.3 0.4 0.5 0.6]
+for i=1:7
+ A(1,i)=-1+1.*x(1,i)-1.5.*x(1,i).*x(1,i)+0.5.*x(1,i).*x(1,i).*x(1,i)-0.125.*x(1,i).*x(1,i).*x(1,i).*x(1,i)
+ B(1,i)=-3.*exp(-x(1,i))-2*x(1,i)+2
+end
+for i=1:7
+T=[x(1,i), A(1,i), B(1,i), B(1,i)-A(1,i)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH6/EX6.3/Table_6_2.sce b/413/CH6/EX6.3/Table_6_2.sce new file mode 100644 index 000000000..0b393ef58 --- /dev/null +++ b/413/CH6/EX6.3/Table_6_2.sce @@ -0,0 +1,14 @@ +clc
+clear
+x=[0 0.1 0.2 0.3 0.4 ]
+y(1,1)=-1
+for i=1:5
+ B(1,i)=(-2*x(1,i)-y(1,i))
+ C(1,i)=0.1*B(1,i)
+ y(1,i+1)=y(1,i)+C(1,i)
+
+end
+for i=1:5
+T=[x(1,i), y(1,i), B(1,i),C(1,i)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH6/EX6.4/Table_6_3.sce b/413/CH6/EX6.4/Table_6_3.sce new file mode 100644 index 000000000..b3ebebfad --- /dev/null +++ b/413/CH6/EX6.4/Table_6_3.sce @@ -0,0 +1,18 @@ +clc
+clear
+x=[0 0.1 0.2 0.3 0.4 0.5]
+y(1,1)=-1
+for i=1:5
+ B(1,i)=(-2*x(1,i)-y(1,i))
+ C(1,i)=0.1*B(1,i)
+ y(1,i+1)=y(1,i)+C(1,i)
+ D(1,i)=y(1,i+1)
+ E(1,i)=0.1*B(1,i)
+ F(1,i)=0.1*(-2*x(1,i+1)-y(1,i+1))
+ G(1,i)=(E(1,i)+F(1,i))/2
+ y(1,i+1)=y(1,i)+G(1,i)
+end
+for i=1:5
+T=[x(1,i), y(1,i), C(1,i),D(1,i),F(1,i),G(1,i),y(1,i+1)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH6/EX6.5/Table_6_4.sce b/413/CH6/EX6.5/Table_6_4.sce new file mode 100644 index 000000000..50ef64a56 --- /dev/null +++ b/413/CH6/EX6.5/Table_6_4.sce @@ -0,0 +1,17 @@ +clc
+clear
+x=[0 0.1 0.2 0.3 0.4 0.5 0.6]
+h=0.1
+y(1,1)=-1
+for i=1:6
+ k1(1,i)=h*(-2*x(1,i)-y(1,i))
+ k2(1,i)=h*(-2*(x(1,i)+h/2)-(y(1,i)+k1(1,i)/2))
+ k3(1,i)=h*(-2*(x(1,i)+h/2)-(y(1,i)+k2(1,i)/2))
+ k4(1,i)=h*(-2*(x(1,i)+h)-(y(1,i)+k3(1,i)))
+ kA(1,i)=(k1(1,i)+2*k2(1,i)+2*k3(1,i)+k4(1,i))/6
+ y(1,i+1)=y(1,i)+kA(1,i)
+end
+for i=1:6
+T=[x(1,i), y(1,i), k1(1,i),k2(1,i),k3(1,i),k4(1,i),kA(1,i)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH6/EX6.6/Example_6_2.sce b/413/CH6/EX6.6/Example_6_2.sce new file mode 100644 index 000000000..f08a9cd16 --- /dev/null +++ b/413/CH6/EX6.6/Example_6_2.sce @@ -0,0 +1,20 @@ +// Solving Using Shooting Method
+// u''-(1-x/5)u=x, u(1)=2, u(3)=-1)
+function ydot=f(t, y),
+ ydot=[y(2);
+ t+y(1)*(1-t/5);]
+endfunction
+y0=[2,-1.5]';t0=1;t=1:0.2:3;
+y=ode(y0,t0,t,f)
+
+y1=[2,-3]'
+U=ode(y1,t0,t,f)
+y2=[2,-3.495]'
+V=ode(y2,t0,t,f)
+printf('Table 6.15')
+printf('\n Assume du/dx(1)=-1.5 Assume du/dx(1)=-3 Assume du/dx(1)=-3.495')
+printf('\n x u du/dx x u du/dx x u du/dx ')
+for i=1:11
+ D=[t(1,i), y(1,i),y(2,i),U(1,i),U(2,i),V(1,i),V(2,i)]
+ disp(D)
+end
\ No newline at end of file diff --git a/413/CH6/EX6.7/Example_6_3.sce b/413/CH6/EX6.7/Example_6_3.sce new file mode 100644 index 000000000..26169b05d --- /dev/null +++ b/413/CH6/EX6.7/Example_6_3.sce @@ -0,0 +1,31 @@ +// Solving Using Shooting Method
+// u''-(1-x/5)uu'=x, u(1)=2, u(3)=-1)
+function ydot=f(t, y),
+ ydot=[y(2);
+ t+y(1)*y(2)*(1-t/5);]
+endfunction
+y0=[2,-1.5]';t0=1;t=1:0.2:3;
+y=ode(['rkf'],y0,t0,t,f)
+
+y1=[2,-3]'
+U=ode(['rkf'],y1,t0,t,f)
+y2=[2,-2.2137]'
+V=ode(['rkf'],y2,t0,t,f)
+y11=[2,-1.9460]'
+U1=ode(['rkf'],y11,t0,t,f)
+y21=[2,-2.0215]'
+V1=ode(['rkf'],y21,t0,t,f)
+y111=[2,-2.0162]'
+U11=ode(['rkf'],y111,t0,t,f)
+y211=[2,-2.0161]'
+V11=ode(['rkf'],y211,t0,t,f)
+printf('Table 6.16')
+printf('\n Assume values for du/dx(1) Calculated Values of u(3)')
+T=[y0(2,1) y(1,11);
+ y1(2,1) U(1,11);
+ y2(2,1) V(1,11);
+ y11(2,1) U1(1,11);
+ y21(2,1) V1(1,11);
+ y111(2,1) U11(1,11);
+ y211(2,1) V11(1,11);]
+disp(T)
diff --git a/413/CH6/EX6.8/Table_6_7.sce b/413/CH6/EX6.8/Table_6_7.sce new file mode 100644 index 000000000..f466b41a8 --- /dev/null +++ b/413/CH6/EX6.8/Table_6_7.sce @@ -0,0 +1,21 @@ +clc
+clear
+x=[0 0.2 0.4 0.6 0.8]
+h=0.2
+y(1,1)=-1
+for i=1:4
+ k1(1,i)=h*(-2*x(1,i)-y(1,i))
+ k2(1,i)=h*(-2*(x(1,i)+h/4)-(y(1,i)+k1(1,i)/4))
+ k3(1,i)=h*(-2*(x(1,i)+(3*h)/8)-(y(1,i)+(3*k1(1,i))/32+(9*k2(1,i))/32))
+ k4(1,i)=h*(-2*(x(1,i)+(12*h)/13)-(y(1,i)+(1932*k1(1,i))/2197-(7200*k2(1,i))/2197+(7296*k3(1,i))/2197))
+ k5(1,i)=h*(-2*(x(1,i)+(h))-(y(1,i)+(439*k1(1,i))/216-(8*k2(1,i))+(3680*k3(1,i))/513-(845*k4(1,i)/4104)))
+ k6(1,i)=h*(-2*(x(1,i)+(h/2))-(y(1,i)-(8*k1(1,i))/27+(2*k2(1,i))-(3544*k3(1,i))/2565+(1859*k4(1,i)/4104)-11*k5(1,i)/40))
+ kA(1,i)=(16*k1(1,i)/135+6656*k3(1,i)/12825+28561*k4(1,i)/56430-9*k5(1,i)/50+2*k6(1,i)/55)
+ y(1,i+1)=y(1,i)+kA(1,i)
+ B(1,i)=-3.*exp(-x(1,i))-2*x(1,i)+2
+ C(1,i)=-2*x(1,i)-y(1,i)
+end
+for i=1:3
+T=[x(1,i), y(1,i),B(1,i) ,C(1,i)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH6/EX6.9/Table_6_8.sce b/413/CH6/EX6.9/Table_6_8.sce new file mode 100644 index 000000000..47262094b --- /dev/null +++ b/413/CH6/EX6.9/Table_6_8.sce @@ -0,0 +1,19 @@ +x=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8]
+h=0.1
+y(1,1)=-1
+for i=1:7
+ k1(1,i)=h*(-2*x(1,i)-y(1,i))
+ k2(1,i)=h*(-2*(x(1,i)+h/4)-(y(1,i)+k1(1,i)/4))
+ k3(1,i)=h*(-2*(x(1,i)+(3*h)/8)-(y(1,i)+(3*k1(1,i))/32+(9*k2(1,i))/32))
+ k4(1,i)=h*(-2*(x(1,i)+(12*h)/13)-(y(1,i)+(1932*k1(1,i))/2197-(7200*k2(1,i))/2197+(7296*k3(1,i))/2197))
+ k5(1,i)=h*(-2*(x(1,i)+(h))-(y(1,i)+(439*k1(1,i))/216-(8*k2(1,i))+(3680*k3(1,i))/513-(845*k4(1,i)/4104)))
+ k6(1,i)=h*(-2*(x(1,i)+(h/2))-(y(1,i)-(8*k1(1,i))/27+(2*k2(1,i))-(3544*k3(1,i))/2565+(1859*k4(1,i)/4104)-11*k5(1,i)/40))
+ kA(1,i)=(16*k1(1,i)/135+6656*k3(1,i)/12825+28561*k4(1,i)/56430-9*k5(1,i)/50+2*k6(1,i)/55)
+ y(1,i+1)=y(1,i)+kA(1,i)
+ B(1,i)=-3.*exp(-x(1,i))-2*x(1,i)+2
+ C(1,i)=-2*x(1,i)-y(1,i)
+end
+for i=1:6
+T=[x(1,i), y(1,i),B(1,i) ,C(1,i)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH7/EX7.1/Example_7_1.sce b/413/CH7/EX7.1/Example_7_1.sce new file mode 100644 index 000000000..69dee877d --- /dev/null +++ b/413/CH7/EX7.1/Example_7_1.sce @@ -0,0 +1,21 @@ +clc
+clear
+x=-3
+function a=f(x)
+ a=exp(x)+2-cos(x);
+endfunction
+h=1
+ y=f(x)
+y1=f(x+h)
+while(abs(y-y1)>=0.00001)
+ y=f(x)
+ y1=f(x+h)
+ while(y>y1)
+ y=f(x)
+ y1=f(x+h)
+ T=[x+h, y1]
+ disp(T)
+ x=x+h
+ end
+ h=-h/4
+ end
\ No newline at end of file diff --git a/413/CH7/EX7.2/Example_7_2.sce b/413/CH7/EX7.2/Example_7_2.sce new file mode 100644 index 000000000..2fd122a96 --- /dev/null +++ b/413/CH7/EX7.2/Example_7_2.sce @@ -0,0 +1,30 @@ +clc
+clear
+a=-3
+b=1
+r=0.618034
+function a=f(x)
+ a=exp(x)+2-cos(x);
+endfunction
+xl=a+(1-r)*(b-a)
+xr=a+r*(b-a)
+FL=f(xl)
+FR=f(xr)
+while (abs(xr-xl)>0.001)
+ T=[xl,xr,FL,FR,a,b,a-b]
+ disp(T)
+ if(FR >FL)
+ b=xr
+ xr=xl
+ FR=FL
+ xl=a+(1-r)*(b-a)
+ FL=f(xl)
+ else
+ a=xl
+ xl=xr
+ FL=FR
+ xr=a+r*(b-a)
+ FR=f(xr)
+ end
+
+end
\ No newline at end of file diff --git a/413/CH7/EX7.3/Example_7_3.sce b/413/CH7/EX7.3/Example_7_3.sce new file mode 100644 index 000000000..906baed12 --- /dev/null +++ b/413/CH7/EX7.3/Example_7_3.sce @@ -0,0 +1,24 @@ +clc
+clear
+A=[5 8]
+B=[3 4
+ 2 5]
+C=[12
+ 10]
+printf('The Primal:')
+printf('\nMax f = %dx1+ %dx2',A(1,1),A(1,2))
+
+for i=1:2
+printf('\n%dx1 +%dx2<=%d', B(i,1),B(i,2),C(i,1))
+end
+printf('\nx1, x2>=0')
+A=A'
+B=B'
+C=C'
+printf('\n\nThe Dual:')
+printf('\nMin f = %dy1+ %dy2',C(1,1),C(1,2))
+
+for i=1:2
+printf('\n%dy1 +%dy2>=%d', B(i,1),B(i,2),A(i,1))
+end
+printf('\ny1, y2>=0')
\ No newline at end of file diff --git a/413/CH8/EX8.1/Example_8_1.sce b/413/CH8/EX8.1/Example_8_1.sce new file mode 100644 index 000000000..99cb72ca1 --- /dev/null +++ b/413/CH8/EX8.1/Example_8_1.sce @@ -0,0 +1,49 @@ +clc
+clear
+A=[-4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
+1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
+0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
+0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
+0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
+0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0
+0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0
+1 0 0 0 0 0 0 -4 1 0 0 0 0 0 1 0 0 0 0 0 0
+0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0
+0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0
+0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0
+0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0
+0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0
+0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1
+0 0 0 0 0 0 0 1 0 0 0 0 0 0 -4 1 0 0 0 0 0
+0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0
+0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0
+0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0
+0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0
+0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1
+0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 ]
+B=[0
+0
+0
+0
+0
+0
+-100
+0
+0
+0
+0
+0
+0
+-100
+0
+0
+0
+0
+0
+0
+-100]
+X=A\B
+for i=1:7
+T=[i, X(i,1), X(i+7,1),X(i+14, 1 )]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH8/EX8.2/Example_8_2.sce b/413/CH8/EX8.2/Example_8_2.sce new file mode 100644 index 000000000..0bb592279 --- /dev/null +++ b/413/CH8/EX8.2/Example_8_2.sce @@ -0,0 +1,47 @@ +clc
+clear
+A=[-4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
+1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
+0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
+0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
+0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
+0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0
+0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0 0 0
+1 0 0 0 0 0 0 -4 1 0 0 0 0 0 1 0 0 0 0 0 0
+0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0 0
+0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0 0
+0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0 0
+0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0 0
+0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 0
+0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1
+0 0 0 0 0 0 0 1 0 0 0 0 0 0 -4 1 0 0 0 0 0
+0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0 0
+0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0 0
+0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0 0
+0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1 0
+0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 1
+0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -4 ]
+B=[0
+0
+0
+0
+0
+0
+-100
+0
+0
+0
+0
+0
+0
+-100
+0
+0
+0
+0
+0
+0
+-100]
+X=A\B
+
+disp(X)
diff --git a/413/CH8/EX8.3/Example_8_3.sce b/413/CH8/EX8.3/Example_8_3.sce new file mode 100644 index 000000000..e8f933a6a --- /dev/null +++ b/413/CH8/EX8.3/Example_8_3.sce @@ -0,0 +1,20 @@ +clc
+clear
+A=[6 -2 1; -2 7 2; 1 2 5]
+b=[11 5 -1]
+D=[6 0 0; 0 7 0; 0 0 -5]
+L=[0 0 0; -2 0 0; 1 2 0]
+U=[0 -2 1; 0 0 2; 0 0 0]
+DI=inv(D)
+printf('For Jacobi method, we need to compute the eigen value of this matrix')
+B=DI*(L+U)
+disp(B)
+T=spec(B)
+disp(T)
+printf(' Magnitude of Largest eigenvaue is %f',abs(T(2,1)))
+printf('\n\nFor Gauss-Seidel method, we need to compute the eigen value of this matrix')
+B=inv(L+D)*U
+disp(B)
+T=spec(B)
+disp(T)
+printf(' Magnitude of Largest eigenvaue is %f',abs(T(2,1)))
\ No newline at end of file diff --git a/413/CH8/EX8.4/Example_8_4.sce b/413/CH8/EX8.4/Example_8_4.sce new file mode 100644 index 000000000..829bb9cad --- /dev/null +++ b/413/CH8/EX8.4/Example_8_4.sce @@ -0,0 +1,40 @@ +clc
+clear
+for i=1:35
+ for j=1:35
+ A(i,j)=0
+ end
+end
+for i=1:35
+ A(i,i)=-4
+end
+for i=1:34
+ A(i,i+1)=1
+end
+for i=2:34
+ A(i,i-1)=1
+end
+for i=6:5:30
+ A(i,i-1)=0
+end
+for i=1:30
+ A(i,i+5)=1
+end
+for i=1:30
+ A(i+5,i)=1
+end
+for i=5:5:35
+ A(i,i+1)=0
+end
+
+disp(A)
+for i=1:35
+ B(i,1)=-2
+end
+
+X=A\B
+disp(X)
+for i=1:5:35
+T=[ X(i,1), X(i+2,1),X(i+3, 1), X(i+4,1), X(i+5,1)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH8/EX8.5/Example_8_5.sce b/413/CH8/EX8.5/Example_8_5.sce new file mode 100644 index 000000000..168ae735c --- /dev/null +++ b/413/CH8/EX8.5/Example_8_5.sce @@ -0,0 +1,46 @@ +clc
+clear
+for i=1:35
+ for j=1:35
+ A(i,j)=0
+ end
+end
+
+
+for i=1:34
+ A(i,i+1)=1
+end
+
+for i=2:35
+ A(i,i-1)=1
+end
+
+for i=6:5:30
+ A(i,i-1)=0
+end
+
+for i=1:30
+ A(i,i+5)=1
+end
+for i=1:30
+ A(i+5,i)=1
+end
+
+for i=5:5:30
+ A(i,i+1)=0
+end
+
+for i=1:35
+ A(i,i)=-4
+end
+disp(A)
+for i=1:35
+ B(i,1)=-2
+end
+
+X=A\B
+
+for i=1:5:35
+T=[ X(i,1), X(i+1,1),X(i+2, 1), X(i+3,1), X(i+4,1)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH8/EX8.6/Example_8_6.sce b/413/CH8/EX8.6/Example_8_6.sce new file mode 100644 index 000000000..2f09087e6 --- /dev/null +++ b/413/CH8/EX8.6/Example_8_6.sce @@ -0,0 +1,80 @@ +clc
+clear
+for i=1:60
+ for j=1:60
+ A(i,j)=0
+ end
+end
+for i=2:9
+ A(i,i)=-1
+ A(i,10+i)=1
+end
+for i=1:10:51
+ A(i,i)=1
+end
+for i=10:10:60
+ A(i,i)=1
+end
+for i=12:19
+ A(i,i-10)=1
+ A(i,i-1)=1
+ A(i,i)=-4
+ A(i,i+1)=1
+ A(i,i+10)=1
+end
+for i=22:29
+ A(i,i-10)=1
+ A(i,i-1)=1
+ A(i,i)=-4
+ A(i,i+1)=1
+ A(i,i+10)=1
+end
+for i=32:39
+ A(i,i-10)=1
+ A(i,i-1)=1
+ A(i,i)=-4
+ A(i,i+1)=1
+ A(i,i+10)=1
+end
+for i=42:49
+ A(i,i-10)=1
+ A(i,i-1)=1
+ A(i,i)=-4
+ A(i,i+1)=1
+ A(i,i+10)=1
+end
+for i=52:59
+ A(i,i-10)=-1
+ A(i,i)=(1+(2*0.073)/0.16)
+end
+
+disp(A)
+for i=2:9
+ B(i,1)=30
+end
+for i=1:10:51
+ B(i,1)=20
+end
+for i=10:10:60
+ B(i,1)=20
+end
+for i=12:19
+ B(i,1)=0.6/(20*0.16)
+end
+for i=22:29
+ B(i,1)=0.6/(20*0.16)
+end
+for i=32:39
+ B(i,1)=0.6/(20*0.16)
+end
+for i=42:49
+ B(i,1)=0.6/(20*0.16)
+end
+for i=52:59
+ B(i,1)=25*(2*0.073)/0.16
+end
+X=A\B
+for i=1:10:60
+T=[ X(i,1), X(i+1,1),X(i+2, 1), X(i+3,1), X(i+4,1),X(i+5,1),X(i+6,1),X(i+7,1),X(i+8,1),X(i+9,1)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH9/EX9.1/Example_9_1.sce b/413/CH9/EX9.1/Example_9_1.sce new file mode 100644 index 000000000..e14a16fe9 --- /dev/null +++ b/413/CH9/EX9.1/Example_9_1.sce @@ -0,0 +1,16 @@ +clc
+clear
+printf('Solve the equation y''+y=3X^2, with boundary points (0,0) and (2, 3.5)')
+printf('\nCompare computed value form Rayleigh-Ritz Method vs Analytic result')
+P=0
+X(1,1)=0
+for i=1:20
+ X(1,i+1)=0.1+P
+ P=X(1,i+1)
+end
+for i=1:21
+ A(1,i)=(119/152).*X(1,i).*X(1,i).*X(1,i)-(46/57)*X(1,i).*X(1,i)+(53/228)*X(1,i)
+B(1,i)=6*cos(X(1,i))+3*(X(1,i).*X(1,i)-2)
+T=[X(1,i), B(1,i), A(1,i), B(1,i)-A(1,i)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH9/EX9.2/Example_9_2.sce b/413/CH9/EX9.2/Example_9_2.sce new file mode 100644 index 000000000..81bbf701d --- /dev/null +++ b/413/CH9/EX9.2/Example_9_2.sce @@ -0,0 +1,16 @@ +clc
+clear
+printf('Solve the equation y''+y=3X^2, with boundary points (0,0) and (2, 3.5)')
+printf('\nCompare computed value form Collocation Method vs Analytic result')
+P=0
+X(1,1)=0
+for i=1:20
+ X(1,i+1)=0.1+P
+ P=X(1,i+1)
+end
+for i=1:21
+ A(1,i)=(425/509).*X(1,i).*X(1,i).*X(1,i)-(61607/55481)*X(1,i).*X(1,i)+(140023/221924)*X(1,i)
+B(1,i)=6*cos(X(1,i))+3*(X(1,i).*X(1,i)-2)
+T=[X(1,i), B(1,i), A(1,i), B(1,i)-A(1,i)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH9/EX9.3/Example_9_3.sce b/413/CH9/EX9.3/Example_9_3.sce new file mode 100644 index 000000000..0137d961b --- /dev/null +++ b/413/CH9/EX9.3/Example_9_3.sce @@ -0,0 +1,16 @@ +clc
+clear
+printf('Solve the equation y''+y=3X^2, with boundary points (0,0) and (2, 3.5)')
+printf('\nCompare computed value form The Galerkin Method vs Analytic result')
+P=0
+X(1,1)=0
+for i=1:20
+ X(1,i+1)=0.1+P
+ P=X(1,i+1)
+end
+for i=1:21
+ A(1,i)=(101/152).*X(1,i).*X(1,i).*X(1,i)-(103/228)*X(1,i).*X(1,i)+(1/228)*X(1,i)
+B(1,i)=6*cos(X(1,i))+3*(X(1,i).*X(1,i)-2)
+T=[X(1,i), B(1,i), A(1,i), B(1,i)-A(1,i)]
+disp(T)
+end
\ No newline at end of file diff --git a/413/CH9/EX9.4/Example_9_4.sce b/413/CH9/EX9.4/Example_9_4.sce new file mode 100644 index 000000000..d3aea38b8 --- /dev/null +++ b/413/CH9/EX9.4/Example_9_4.sce @@ -0,0 +1,40 @@ +clc
+clear
+printf('Solve the equation y''+y=3X^2, with boundary points (0,0) and (2, 3.5)')
+printf('\n Subdivide into seven elements that join at x=0.4, 0.7, 1.1, 1.3 and 1.6')
+printf('\n Augmented matrix')
+P=[2.367 -2.567 0 0 0 0 0 0 -0.024
+-2.567 5.6 -3.383 0 0 0 0 0 -0.160
+0 -3.383 8.167 -5.033 0 0 0 0 -0.328
+0 0 -5.033 9.867 -5.033 0 0 0 -0.492
+0 0 0 -5.033 9.867 -5.033 0 0 -0.732
+0 0 0 0 -5.033 8.167 -3.383 0 -1.378
+0 0 0 0 0 -3.383 5.600 -2.567 -2.89
+0 0 0 0 0 0 -2.567 2.367 -1.944]
+disp(P)
+printf('Matrix after ajjusting boundary condition')
+T=[ 5.6 -3.383 0 0 0 0 -0.160
+ -3.383 8.167 -5.033 0 0 0 -0.328
+ 0 -5.033 9.867 -5.033 0 0 -0.492
+ 0 0 -5.033 9.867 -5.033 0 -0.732
+ 0 0 0 -5.033 8.167 -3.383 -1.378
+ 0 0 0 0 -3.383 5.600 6.094]
+ disp(T)
+ A=[ 5.6 -3.383 0 0 0 0
+ -3.383 8.167 -5.033 0 0 0
+ 0 -5.033 9.867 -5.033 0 0
+ 0 0 -5.033 9.867 -5.033 0
+ 0 0 0 -5.033 8.167 -3.383
+ 0 0 0 0 -3.383 5.600 ]
+
+ B=[-0.160 -0.328 -0.492 -0.732 -1.378 6.094]'
+ S=A\B
+printf('The table showing the analytical solution and the errors of our computation')
+
+ X=[0.4 0.7 0.9 1.1 1.3 1.6]
+ for i=1:6
+ B(1,i)=6*cos(X(1,i))+3*(X(1,i).*X(1,i)-2)
+ T=[X(1,i), S(i,1), B(1,i), B(1,i)-S(i,1)]
+disp(T)
+ end
+
\ No newline at end of file diff --git a/413/CH9/EX9.5/Example_9_5.sce b/413/CH9/EX9.5/Example_9_5.sce new file mode 100644 index 000000000..41801f555 --- /dev/null +++ b/413/CH9/EX9.5/Example_9_5.sce @@ -0,0 +1,35 @@ +clc
+clear
+//printf('(Solve the equation y''-(x+1)y=e^-x(X^2-x+2), with Neumann boundary conditions y'(2)=0, y'(4)=-0.036631)')
+
+printf('\n Augmented matrix')
+P=[2.542 -1.729 0 0 0 0.127
+-1.729 5.167 -1.688 0 0 0.236
+0 -1.688 5.333 -1.646 0 0.199
+0 0 -1.646 5.5 -1.604 0.163
+0 0 0 -1.604 2.792 0.072 ]
+disp(P)
+printf('Matrix after ajjusting boundary condition')
+T=[ 2.542 -1.729 0 0 0 0.127
+-1.729 5.167 -1.688 0 0 0.236
+0 -1.688 5.333 -1.646 0 0.199
+0 0 -1.646 5.5 -1.604 0.163
+0 0 0 -1.604 2.792 0.036 ]
+ disp(T)
+ A=[ 2.542 -1.729 0 0 0
+-1.729 5.167 -1.688 0 0
+0 -1.688 5.333 -1.646 0
+0 0 -1.646 5.5 -1.604
+0 0 0 -1.604 2.792 ]
+
+ B=[0.127 0.236 0.199 0.163 0.036]'
+ S=A\B
+printf('The table showing the analytical solution and the errors of our computation')
+
+ X=[2.0 2.5 3.0 3.5 4]
+ for i=1:5
+ B(1,i)=exp(-X(1,i))*(X(1,i)-1)
+ T=[X(1,i), S(i,1), B(1,i), B(1,i)-S(i,1)]
+disp(T)
+ end
+
\ No newline at end of file diff --git a/413/CH9/EX9.6/Example_9_6.sce b/413/CH9/EX9.6/Example_9_6.sce new file mode 100644 index 000000000..4e747c85f --- /dev/null +++ b/413/CH9/EX9.6/Example_9_6.sce @@ -0,0 +1,19 @@ +clc
+clear
+printf('For the triangular element with nodes r s and t Find {a} {N} and v(0.8, 0.4)')
+M=[1 0 0; 1 2 0; 1 0 1]
+printf('\n M=')
+disp(M)
+Minv=inv(M)
+printf('\n inverse of M')
+disp(Minv)
+C=[ 100 200 300]'
+printf('\n C')
+disp(C)
+a=Minv*C
+printf('\n {a}=Inverse of M* C')
+printf('\n {a}=')
+disp(a)
+v=a(1,1)+a(2,1)*0.8+a(3,1)*0.4
+printf('v(0.8,0.4)=')
+disp(v)
\ No newline at end of file |