summaryrefslogtreecommitdiff
path: root/964/CH21
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /964/CH21
downloadScilab-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/CH21')
-rwxr-xr-x964/CH21/EX21.1/21_1.sce25
-rwxr-xr-x964/CH21/EX21.2/21_2.sce29
-rwxr-xr-x964/CH21/EX21.3/21_3.sce141
-rwxr-xr-x964/CH21/EX21.4/21_4.sce30
-rwxr-xr-x964/CH21/EX21.5/21_5.sce41
-rwxr-xr-x964/CH21/EX21.6/21_6.sce52
-rwxr-xr-x964/CH21/EX21.7/21_7.sce19
-rwxr-xr-x964/CH21/EX21.8/21_8.sce22
-rwxr-xr-x964/CH21/EX21.9/21_9.sce34
9 files changed, 393 insertions, 0 deletions
diff --git a/964/CH21/EX21.1/21_1.sce b/964/CH21/EX21.1/21_1.sce
new file mode 100755
index 000000000..5f011f8bc
--- /dev/null
+++ b/964/CH21/EX21.1/21_1.sce
@@ -0,0 +1,25 @@
+clc;
+clear;
+function y=f(x)
+ y=(0.2+25*x-200*x^2+675*x^3-900*x^4+400*x^5)
+endfunction
+tval=1.640533;
+a=0;
+b=0.8;
+fa=f(a);
+fb=f(b);
+l=(b-a)*((fa+fb)/2);
+Et=tval-l;//error
+et=Et*100/tval;//percent relative error
+
+//by using approximate error estimate
+
+//the second derivative of f
+function y=g(x)
+ y=-400+4050*x-10800*x^2+8000*x^3
+endfunction
+f2x=intg(0,0.8,g)/(b-a);//average value of second derivative
+Ea=-(1/12)*(f2x)*(b-a)^3;
+disp(Et,"The Error Et=")
+disp("%",et,"The percent relative error et=")
+disp(Ea,"The approximate error estimate without using the true value=")
diff --git a/964/CH21/EX21.2/21_2.sce b/964/CH21/EX21.2/21_2.sce
new file mode 100755
index 000000000..1f2e72374
--- /dev/null
+++ b/964/CH21/EX21.2/21_2.sce
@@ -0,0 +1,29 @@
+clc;
+clear;
+function y=f(x)
+ y=(0.2+25*x-200*x^2+675*x^3-900*x^4+400*x^5)
+endfunction
+a=0;
+b=0.8;
+tval=1.640533;
+n=2;
+h=(b-a)/n;
+fa=f(a);
+fb=f(b);
+fh=f(h);
+l=(b-a)*(fa+2*fh+fb)/(2*n);
+Et=tval-l;//error
+et=Et*100/tval;//percent relative error
+
+//by using approximate error estimate
+
+//the second derivative of f
+function y=g(x)
+ y=-400+4050*x-10800*x^2+8000*x^3
+endfunction
+f2x=intg(0,0.8,g)/(b-a);//average value of second derivative
+Ea=-(1/12)*(f2x)*(b-a)^3/(n^2);
+disp(Et,"The Error Et=")
+disp("%",et,"The percent relative error et=")
+disp(Ea,"The approximate error estimate without using the true value=")
+
diff --git a/964/CH21/EX21.3/21_3.sce b/964/CH21/EX21.3/21_3.sce
new file mode 100755
index 000000000..5cbca050b
--- /dev/null
+++ b/964/CH21/EX21.3/21_3.sce
@@ -0,0 +1,141 @@
+clc;
+clear;
+g=9.8;//m/s^2; acceleration due to gravity
+m=68.1;//kg
+c=12.5;//kg/sec; drag coefficient
+function v=f(t)
+ v=g*m*(1-exp(-c*t/m))/c
+endfunction
+tval=289.43515;//m
+a=0;
+b=10;
+fa=f(a);
+fb=f(b);
+for i=10:10:20
+ n=i;
+ h=(b-a)/n;
+ disp(i,"No. of segments=")
+ disp(h,"Segment size=")
+ j=a+h;
+ s=0;
+ while j<b
+ s=s+f(j);
+ j=j+h;
+ end
+ l=(b-a)*(fa+2*s+fb)/(2*n);
+ Et=tval-l;//error
+ et=Et*100/tval;//percent relative error
+ disp("m",l,"Estimated d=")
+ disp(et,"et(%)")
+ disp("---------------------------------------------------------")
+end
+for i=50:50:100
+ n=i;
+ h=(b-a)/n;
+ disp(i,"No. of segments=")
+ disp(h,"Segment size=")
+ j=a+h;
+ s=0;
+ while j<b
+ s=s+f(j);
+ j=j+h;
+ end
+ l=(b-a)*(fa+2*s+fb)/(2*n);
+ Et=tval-l;//error
+ et=Et*100/tval;//percent relative error
+ disp("m",l,"Estimated d=")
+ disp(et,"et(%)")
+ disp("---------------------------------------------------------")
+end
+for i=100:100:200
+ n=i;
+ h=(b-a)/n;
+ disp(i,"No. of segments=")
+ disp(h,"Segment size=")
+ j=a+h;
+ s=0;
+ while j<b
+ s=s+f(j);
+ j=j+h;
+ end
+ l=(b-a)*(fa+2*s+fb)/(2*n);
+ Et=tval-l;//error
+ et=Et*100/tval;//percent relative error
+ disp("m",l,"Estimated d=")
+ disp(et,"et(%)")
+ disp("---------------------------------------------------------")
+end
+for i=200:300:500
+ n=i;
+ h=(b-a)/n;
+ disp(i,"No. of segments=")
+ disp(h,"Segment size=")
+ j=a+h;
+ s=0;
+ while j<b
+ s=s+f(j);
+ j=j+h;
+ end
+ l=(b-a)*(fa+2*s+fb)/(2*n);
+ Et=tval-l;//error
+ et=Et*100/tval;//percent relative error
+ disp("m",l,"Estimated d=")
+ disp(et,"et(%)")
+ disp("---------------------------------------------------------")
+end
+for i=1000:1000:2000
+ n=i;
+ h=(b-a)/n;
+ disp(i,"No. of segments=")
+ disp(h,"Segment size=")
+ j=a+h;
+ s=0;
+ while j<b
+ s=s+f(j);
+ j=j+h;
+ end
+ l=(b-a)*(fa+2*s+fb)/(2*n);
+ Et=tval-l;//error
+ et=Et*100/tval;//percent relative error
+ disp("m",l,"Estimated d=")
+ disp(et,"et(%)")
+ disp("---------------------------------------------------------")
+end
+for i=2000:3000:5000
+ n=i;
+ h=(b-a)/n;
+ disp(i,"No. of segments=")
+ disp(h,"Segment size=")
+ j=a+h;
+ s=0;
+ while j<b
+ s=s+f(j);
+ j=j+h;
+ end
+ l=(b-a)*(fa+2*s+fb)/(2*n);
+ Et=tval-l;//error
+ et=Et*100/tval;//percent relative error
+ disp("m",l,"Estimated d=")
+ disp(et,"et(%)")
+ disp("---------------------------------------------------------")
+end
+for i=5000:5000:10000
+ n=i;
+ h=(b-a)/n;
+ disp(i,"No. of segments=")
+ disp(h,"Segment size=")
+ j=a+h;
+ s=0;
+ while j<b
+ s=s+f(j);
+ j=j+h;
+ end
+ l=(b-a)*(fa+2*s+fb)/(2*n);
+ Et=tval-l;//error
+ et=Et*100/tval;//percent relative error
+ disp("m",l,"Estimated d=")
+ disp(et,"et(%)")
+ disp("---------------------------------------------------------")
+end
+
+
diff --git a/964/CH21/EX21.4/21_4.sce b/964/CH21/EX21.4/21_4.sce
new file mode 100755
index 000000000..efa2bba58
--- /dev/null
+++ b/964/CH21/EX21.4/21_4.sce
@@ -0,0 +1,30 @@
+clc;
+clear;
+function y=f(x)
+ y=(0.2+25*x-200*x^2+675*x^3-900*x^4+400*x^5)
+endfunction
+a=0;
+b=0.8;
+tval=1.640533;
+n=2;
+h=(b-a)/n;
+fa=f(a);
+fb=f(b);
+fh=f(h);
+l=(b-a)*(fa+4*fh+fb)/(3*n);
+disp(l,"l=")
+Et=tval-l;//error
+et=Et*100/tval;//percent relative error
+
+//by using approximate error estimate
+
+//the fourth derivative of f
+function y=g(x)
+ y=-21600+48000*x
+endfunction
+f4x=intg(0,0.8,g)/(b-a);//average value of fourth derivative
+Ea=-(1/2880)*(f4x)*(b-a)^5;
+disp(Et,"The Error Et=")
+disp("%",et,"The percent relative error et=")
+disp(Ea,"The approximate error estimate without using the true value=")
+
diff --git a/964/CH21/EX21.5/21_5.sce b/964/CH21/EX21.5/21_5.sce
new file mode 100755
index 000000000..e5de4a916
--- /dev/null
+++ b/964/CH21/EX21.5/21_5.sce
@@ -0,0 +1,41 @@
+clc;
+clear;
+function y=f(x)
+ y=(0.2+25*x-200*x^2+675*x^3-900*x^4+400*x^5)
+endfunction
+a=0;
+b=0.8;
+tval=1.640533;
+n=4;
+h=(b-a)/n;
+fa=f(a);
+fb=f(b);
+j=a+h;
+s=0;
+count=1;
+while j<b
+ if (-1)^count==-1 then
+ s=s+4*f(j);
+ else
+ s=s+2*f(j);
+ end
+ count=count+1;
+ j=j+h;
+end
+l=(b-a)*(fa+s+fb)/(3*n);
+disp(l,"l=")
+Et=tval-l;//error
+et=Et*100/tval;//percent relative error
+
+//by using approximate error estimate
+
+//the fourth derivative of f
+function y=g(x)
+ y=-21600+48000*x
+endfunction
+f4x=intg(0,0.8,g)/(b-a);//average value of fourth derivative
+Ea=-(1/(180*4^4))*(f4x)*(b-a)^5;
+disp(Et,"The Error Et=")
+disp("%",et,"The percent relative error et=")
+disp(Ea,"The approximate error estimate without using the true value=")
+
diff --git a/964/CH21/EX21.6/21_6.sce b/964/CH21/EX21.6/21_6.sce
new file mode 100755
index 000000000..60d21800a
--- /dev/null
+++ b/964/CH21/EX21.6/21_6.sce
@@ -0,0 +1,52 @@
+clc;
+clear;
+function y=f(x)
+ y=(0.2+25*x-200*x^2+675*x^3-900*x^4+400*x^5)
+endfunction
+a=0;
+b=0.8;
+tval=1.640533;
+//part a
+n=3;
+h=(b-a)/n;
+fa=f(a);
+fb=f(b);
+j=a+h;
+s=0;
+count=1;
+while j<b
+ s=s+3*f(j);
+ count=count+1;
+ j=j+h;
+end
+l=(b-a)*(fa+s+fb)/(8);
+disp("Part A:")
+disp(l,"l=")
+Et=tval-l;//error
+et=Et*100/tval;//percent relative error
+
+//by using approximate error estimate
+
+//the fourth derivative of f
+function y=g(x)
+ y=-21600+48000*x
+endfunction
+f4x=intg(0,0.8,g)/(b-a);//average value of fourth derivative
+Ea=-(1/6480)*(f4x)*(b-a)^5;
+disp(Et,"The Error Et=")
+disp("%",et,"The percent relative error et=")
+disp(Ea,"The approximate error estimate without using the true value=")
+
+//part b
+n=5;
+h=(b-a)/n;
+l1=(a+2*h-a)*(fa+4*f(a+h)+f(a+2*h))/6;
+l2=(a+5*h-a-2*h)*(f(a+2*h)+3*(f(a+3*h)+f(a+4*h))+fb)/8;
+l=l1+l2;
+disp("---------------------------------------------------")
+disp("Part B:")
+disp(l,"l=")
+Et=tval-l;//error
+et=Et*100/tval;//percent relative error
+disp(Et,"The Error Et=")
+disp("%",et,"The percent relative error et=")
diff --git a/964/CH21/EX21.7/21_7.sce b/964/CH21/EX21.7/21_7.sce
new file mode 100755
index 000000000..82bc6b812
--- /dev/null
+++ b/964/CH21/EX21.7/21_7.sce
@@ -0,0 +1,19 @@
+clc;
+clear;
+function y=f(x)
+ y=(0.2+25*x-200*x^2+675*x^3-900*x^4+400*x^5)
+endfunction
+tval=1.640533;
+x=[0 0.12 0.22 0.32 0.36 0.4 0.44 0.54 0.64 0.7 0.8];
+for i=1:11
+ func(i)=f(x(i));
+end
+l=0;
+for i=1:10
+ l=l+(x(i+1)-x(i))*(func(i)+func(i+1))/2;
+end
+disp(l,"l=")
+Et=tval-l;//error
+et=Et*100/tval;//percent relative error
+disp(Et,"The Error Et=")
+disp("%",et,"The percent relative error et=")
diff --git a/964/CH21/EX21.8/21_8.sce b/964/CH21/EX21.8/21_8.sce
new file mode 100755
index 000000000..6e46267ad
--- /dev/null
+++ b/964/CH21/EX21.8/21_8.sce
@@ -0,0 +1,22 @@
+clc;
+clear;
+function y=f(x)
+ y=(0.2+25*x-200*x^2+675*x^3-900*x^4+400*x^5)
+endfunction
+tval=1.640533;
+x=[0 0.12 0.22 0.32 0.36 0.4 0.44 0.54 0.64 0.7 0.8];
+for i=1:11
+ func(i)=f(x(i));
+end
+l1=(x(2)-x(1))*((f(x(1))+f(x(2)))/2);
+l2=(x(4)-x(2))*(f(x(4))+4*f(x(3))+f(x(2)))/6;
+l3=(x(7)-x(4))*(f(x(4))+3*(f(x(5))+f(x(6)))+f(x(7)))/8;
+l4=(x(9)-x(7))*(f(x(7))+4*f(x(8))+f(x(9)))/6;
+l5=(x(10)-x(9))*((f(x(10))+f(x(9)))/2);
+l6=(x(11)-x(10))*((f(x(11))+f(x(10)))/2);
+l=l1+l2+l3+l4+l5+l6;
+disp(l,"l=")
+Et=tval-l;//error
+et=Et*100/tval;//percent relative error
+disp(Et,"The Error Et=")
+disp("%",et,"The percent relative error et=")
diff --git a/964/CH21/EX21.9/21_9.sce b/964/CH21/EX21.9/21_9.sce
new file mode 100755
index 000000000..c9a62a048
--- /dev/null
+++ b/964/CH21/EX21.9/21_9.sce
@@ -0,0 +1,34 @@
+clc;
+clear;
+function t=f(x,y)
+ t=2*x*y+2*x-x^2-2*y^2+72
+endfunction
+len=8;//m,length
+wid=6;//m,width
+a=0;
+b=len;
+n=2;
+h=(b-a)/n;
+a1=0;
+b1=wid;
+h1=(b1-a1)/n;
+
+fa=f(a,0);
+fb=f(b,0);
+fh=f(h,0);
+lx1=(b-a)*(fa+2*fh+fb)/(2*n);
+
+fa=f(a,h1);
+fb=f(b,h1);
+fh=f(h,h1);
+lx2=(b-a)*(fa+2*fh+fb)/(2*n);
+
+fa=f(a,b1);
+fb=f(b,b1);
+fh=f(h,b1);
+lx3=(b-a)*(fa+2*fh+fb)/(2*n);
+
+l=(b1-a1)*(lx1+2*lx2+lx3)/(2*n);
+
+avg_temp=l/(len*wid);
+disp(avg_temp,"The average termperature is=")