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 /964/CH4 | |
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 '964/CH4')
-rwxr-xr-x | 964/CH4/EX4.1/4_1.sce | 65 | ||||
-rwxr-xr-x | 964/CH4/EX4.2/4_2.sce | 80 | ||||
-rwxr-xr-x | 964/CH4/EX4.3/4_3.sce | 25 | ||||
-rwxr-xr-x | 964/CH4/EX4.4/4_4.sce | 22 | ||||
-rwxr-xr-x | 964/CH4/EX4.5/4_5.sce | 10 | ||||
-rwxr-xr-x | 964/CH4/EX4.6/4_6.sce | 34 | ||||
-rwxr-xr-x | 964/CH4/EX4.7/4_7.sce | 17 |
7 files changed, 253 insertions, 0 deletions
diff --git a/964/CH4/EX4.1/4_1.sce b/964/CH4/EX4.1/4_1.sce new file mode 100755 index 000000000..146a0dcb6 --- /dev/null +++ b/964/CH4/EX4.1/4_1.sce @@ -0,0 +1,65 @@ +clc;
+clear;
+function y=f(x)
+ y=-0.1*x^4-0.15*x^3-0.5*x^2-0.25*x+1.2;
+endfunction
+xi=0;
+xf=1;
+h=xf-xi;
+fi=f(xi);//function value at xi
+ffa=f(xf);//actual function value at xf
+
+//for n=0, i.e, zero order approximation
+ff=fi;
+Et(1)=ffa-ff;//truncation error at x=1
+disp(fi,"The value of f at x=0 :")
+disp(ff,"The value of f at x=1 due to zero order approximation :")
+disp(Et(1),"Truncation error :")
+disp("----------------------------------------------")
+
+//for n=1, i.e, first order approximation
+deff('y=f1(x)','y=derivative(f,x,order=4)')
+f1i=f1(xi);//value of first derivative of function at xi
+f1f=fi+f1i*h;//value of first derivative of function at xf
+Et(2)=ffa-f1f;//truncation error at x=1
+disp(f1i,"The value of first derivative of f at x=0 :")
+disp(f1f,"The value of f at x=1 due to first order approximation :")
+disp(Et(2),"Truncation error :")
+disp("----------------------------------------------")
+
+
+//for n=2, i.e, second order approximation
+deff('y=f2(x)','y=derivative(f1,x,order=4)')
+f2i=f2(xi);//value of second derivative of function at xi
+f2f=f1f+f2i*(h^2)/factorial(2);//value of second derivative of function at xf
+Et(3)=ffa-f2f;//truncation error at x=1
+disp(f2i,"The value of second derivative of f at x=0 :")
+disp(f2f,"The value of f at x=1 due to second order approximation :")
+disp(Et(3),"Truncation error :")
+disp("----------------------------------------------")
+
+//for n=3, i.e, third order approximation
+deff('y=f3(x)','y=derivative(f2,x,order=4)')
+f3i=f3(xi);//value of third derivative of function at xi
+f3f=f2f+f3i*(h^3)/factorial(3);//value of third derivative of function at xf
+Et(4)=ffa-f3f;//truncation error at x=1
+disp(f3i,"The value of third derivative of f at x=0 :")
+disp(f3f,"The value of f at x=1 due to third order approximation :")
+disp(Et(4),"Truncation error :")
+disp("----------------------------------------------")
+
+//for n=4, i.e, fourth order approximation
+deff('y=f4(x)','y=derivative(f3,x,order=4)')
+f4i=f4(xi);//value of fourth derivative of function at xi
+f4f=f3f+f4i*(h^4)/factorial(4);//value of fourth derivative of function at xf
+Et(5)=ffa-f4f;//truncation error at x=1
+disp(f4i,"The value of fourth derivative of f at x=0 :")
+disp(f4f,"The value of f at x=1 due to fourth order approximation :")
+disp(Et(5),"Truncation error :")
+disp("----------------------------------------------")
+
+
+
+
+
+
diff --git a/964/CH4/EX4.2/4_2.sce b/964/CH4/EX4.2/4_2.sce new file mode 100755 index 000000000..9bd0a1887 --- /dev/null +++ b/964/CH4/EX4.2/4_2.sce @@ -0,0 +1,80 @@ +clc;
+clear;
+function y=f(x)
+ y=cos(x)
+endfunction
+xi=%pi/4;
+xf=%pi/3;
+h=xf-xi;
+fi=f(xi);//function value at xi
+ffa=f(xf);//actual function value at xf
+
+//for n=0, i.e, zero order approximation
+ff=fi;
+et(1)=(ffa-ff)*100/ffa;//percent relative error at x=1
+disp(ff,"The value of f at x=1 due to zero order approximation :")
+disp(et(1),"% relative error :")
+disp("----------------------------------------------")
+
+//for n=1, i.e, first order approximation
+deff('y=f1(x)','y=derivative(f,x,order=4)')
+f1i=f1(xi);//value of first derivative of function at xi
+f1f=fi+f1i*h;//value of first derivative of function at xf
+et(2)=(ffa-f1f)*100/ffa;//% relative error at x=1
+disp(f1f,"The value of f at x=1 due to first order approximation :")
+disp(et(2),"% relative error :")
+disp("----------------------------------------------")
+
+
+//for n=2, i.e, second order approximation
+deff('y=f2(x)','y=derivative(f1,x,order=4)')
+f2i=f2(xi);//value of second derivative of function at xi
+f2f=f1f+f2i*(h^2)/factorial(2);//value of second derivative of function at xf
+et(3)=(ffa-f2f)*100/ffa;//% relative error at x=1
+disp(f2f,"The value of f at x=1 due to second order approximation :")
+disp(et(3),"% relative error :")
+disp("----------------------------------------------")
+
+
+//for n=3, i.e, third order approximation
+deff('y=f3(x)','y=derivative(f2,x,order=4)')
+f3i=f3(xi);//value of third derivative of function at xi
+f3f=f2f+f3i*(h^3)/factorial(3);//value of third derivative of function at xf
+et(4)=(ffa-f3f)*100/ffa;//% relative error at x=1
+disp(f3f,"The value of f at x=1 due to third order approximation :")
+disp(et(4),"% relative error :")
+disp("----------------------------------------------")
+
+
+//for n=4, i.e, fourth order approximation
+deff('y=f4(x)','y=derivative(f3,x,order=4)')
+f4i=f4(xi);//value of fourth derivative of function at xi
+f4f=f3f+f4i*(h^4)/factorial(4);//value of fourth derivative of function at xf
+et(5)=(ffa-f4f)*100/ffa;//% relative error at x=1
+disp(f4f,"The value of f at x=1 due to fourth order approximation :")
+disp(et(5),"% relative error :")
+disp("----------------------------------------------")
+
+
+//for n=5, i.e, fifth order approximation
+f5i=(f4(1.1*xi)-f4(0.9*xi))/(2*0.1);//value of fifth derivative of function at xi (central difference method)
+f5f=f4f+f5i*(h^5)/factorial(5);//value of fifth derivative of function at xf
+et(6)=(ffa-f5f)*100/ffa;//% relative error at x=1
+disp(f5f,"The value of f at x=1 due to fifth order approximation :")
+disp(et(6),"% relative error :")
+disp("----------------------------------------------")
+
+
+//for n=6, i.e, sixth order approximation
+deff('y=f6(x)','y=derivative(f5,x,order=4)')
+f6i=(f4(1.1*xi)-2*f4(xi)+f4(0.9*xi))/(0.1^2);//value of sixth derivative of function at xi (central difference method)
+f6f=f5f+f6i*(h^6)/factorial(6);//value of sixth derivative of function at xf
+et(6)=(ffa-f6f)*100/ffa;//% relative error at x=1
+disp(f6f,"The value of f at x=1 due to sixth order approximation :")
+disp(et(6),"% relative error :")
+disp("----------------------------------------------")
+
+
+
+
+
diff --git a/964/CH4/EX4.3/4_3.sce b/964/CH4/EX4.3/4_3.sce new file mode 100755 index 000000000..40e49d44b --- /dev/null +++ b/964/CH4/EX4.3/4_3.sce @@ -0,0 +1,25 @@ +clc;
+clear;
+m=input("Input value of m:")
+h=input("Input value of h:")
+function y=f(x)
+ y=x^m
+endfunction
+x1=1;
+x2=x1+h;
+fx1=f(x1);
+fx2=fx1+m*(fx1^(m-1))*h;
+if m==1 then
+ R=0;
+else if m==2 then
+ R=2*(h^2)/factorial(2);
+ end
+ if m==3 then
+ R=(6*(x1)*(h^2)/factorial(2))+(6*(h^3)/factorial(3));
+ end
+ if m==4 then
+ R=(12*(x1^2)*(h^2)/factorial(2))+(24*(x1)*(h^3)/factorial(3))+(24*(h^4)/factorial(4));
+ end
+end
+disp(R,"Remainder:",fx2,"The value by first order approximation:")
+disp(f(x2),"True Value at x2:")
\ No newline at end of file diff --git a/964/CH4/EX4.4/4_4.sce b/964/CH4/EX4.4/4_4.sce new file mode 100755 index 000000000..24d01cf3f --- /dev/null +++ b/964/CH4/EX4.4/4_4.sce @@ -0,0 +1,22 @@ +clc;
+clear;
+function y=f(x)
+ y=-0.1*(x^4)-0.15*(x^3)-0.5*(x^2)-0.25*(x)+1.2
+endfunction
+x=0.5;
+h=input("Input h:")
+x1=x-h;
+x2=x+h;
+//forward difference method
+fdx1=(f(x2)-f(x))/h;//derivative at x
+et1=abs((fdx1-derivative(f,x))/derivative(f,x))*100;
+//backward difference method
+fdx2=(f(x)-f(x1))/h;//derivative at x
+et2=abs((fdx2-derivative(f,x))/derivative(f,x))*100;
+//central difference method
+fdx3=(f(x2)-f(x1))/(2*h);//derivative at x
+et3=abs((fdx3-derivative(f,x))/derivative(f,x))*100;
+disp(h,"For h=")
+disp(et1,"and percent error=",fdx1,"Derivative at x by forward difference method=")
+disp(et2,"and percent error=",fdx2,"Derivative at x by backward difference method=")
+disp(et3,"and percent error=",fdx3,"Derivative at x by central difference method=")
\ No newline at end of file diff --git a/964/CH4/EX4.5/4_5.sce b/964/CH4/EX4.5/4_5.sce new file mode 100755 index 000000000..dc308e5a7 --- /dev/null +++ b/964/CH4/EX4.5/4_5.sce @@ -0,0 +1,10 @@ +clc;
+clear;
+function y=f(x)
+ y=x^3
+endfunction
+x=2.5;
+delta=0.01;
+deltafx=abs(derivative(f,x))*delta;
+fx=f(x);
+disp(fx+deltafx,"and",fx-deltafx,"true value is between")
\ No newline at end of file diff --git a/964/CH4/EX4.6/4_6.sce b/964/CH4/EX4.6/4_6.sce new file mode 100755 index 000000000..195fbab85 --- /dev/null +++ b/964/CH4/EX4.6/4_6.sce @@ -0,0 +1,34 @@ +clc;
+clear;
+function y=f(F,L,E,I)
+ y=(F*(L^4))/(8*E*I)
+endfunction
+Fbar=50;//lb/ft
+Lbar=30;//ft
+Ebar=1.5*(10^8);//lb/ft^2
+Ibar=0.06;//ft^4
+deltaF=2;//lb/ft
+deltaL=0.1;//ft
+deltaE=0.01*(10^8);//lb/ft^2
+deltaI=0.0006;//ft^4
+ybar=(Fbar*(Lbar^4))/(8*Ebar*Ibar);
+function y=f1(F)
+ y=(F*(Lbar^4))/(8*Ebar*Ibar)
+endfunction
+function y=f2(L)
+ y=(Fbar*(L^4))/(8*Ebar*Ibar)
+endfunction
+function y=f3(E)
+ y=(Fbar*(Lbar^4))/(8*E*Ibar)
+endfunction
+function y=f4(I)
+ y=(Fbar*(Lbar^4))/(8*Ebar*I)
+endfunction
+
+deltay=abs(derivative(f1,Fbar))*deltaF+abs(derivative(f2,Lbar))*deltaL+abs(derivative(f3,Ebar))*deltaE+abs(derivative(f4,Ibar))*deltaI;
+
+disp(ybar+deltay,"and",ybar-deltay,"The value of y is between:")
+ymin=((Fbar-deltaF)*((Lbar-deltaL)^4))/(8*(Ebar+deltaE)*(Ibar+deltaI));
+ymax=((Fbar+deltaF)*((Lbar+deltaL)^4))/(8*(Ebar-deltaE)*(Ibar-deltaI));
+disp(ymin,"ymin is calculated at lower extremes of F, L, E, I values as =")
+disp(ymax,"ymax is calculated at higher extremes of F, L, E, I values as =")
diff --git a/964/CH4/EX4.7/4_7.sce b/964/CH4/EX4.7/4_7.sce new file mode 100755 index 000000000..242607647 --- /dev/null +++ b/964/CH4/EX4.7/4_7.sce @@ -0,0 +1,17 @@ +clc;
+clear;
+function y=f(x)
+ y=tan(x)
+endfunction
+x1bar=(%pi/2)+0.1*(%pi/2);
+x2bar=(%pi/2)+0.01*(%pi/2);
+//computing condition number for x1bar
+condnum1=x1bar*derivative(f,x1bar)/f(x1bar);
+disp(condnum1,"is:",x1bar,"The condition number of function for x=")
+if abs(condnum1)>1 then disp(x1bar,"Function is ill-conditioned for x=")
+end
+//computing condition number for x2bar
+condnum2=x2bar*derivative(f,x2bar)/f(x2bar);
+disp(condnum2,"is:",x2bar,"The condition number of function for x=")
+if abs(condnum2)>1 then disp(x2bar,"Function is ill-conditioned for x=")
+end
\ No newline at end of file |