summaryrefslogtreecommitdiff
path: root/50/CH5
diff options
context:
space:
mode:
Diffstat (limited to '50/CH5')
-rwxr-xr-x50/CH5/EX5.1/ex_5_1.sce12
-rwxr-xr-x50/CH5/EX5.10/ex_5_10.sce15
-rwxr-xr-x50/CH5/EX5.11/ex_5_11.sce18
-rwxr-xr-x50/CH5/EX5.12/ex_5_12.sce17
-rwxr-xr-x50/CH5/EX5.13/ex_5_13.sce12
-rwxr-xr-x50/CH5/EX5.15/ex_5_15.sce26
-rwxr-xr-x50/CH5/EX5.16/ex_5_16.sce16
-rwxr-xr-x50/CH5/EX5.17/ex_5_17.sce24
-rwxr-xr-x50/CH5/EX5.18/ex_5_18.sce23
-rwxr-xr-x50/CH5/EX5.2/ex_5_2.sce9
-rwxr-xr-x50/CH5/EX5.20/ex_5_20.sce16
-rwxr-xr-x50/CH5/EX5.21/ex_5_21.sce16
-rwxr-xr-x50/CH5/EX5.22/ex_5_22.sce20
-rwxr-xr-x50/CH5/EX5.26/ex_5_26.sce42
-rwxr-xr-x50/CH5/EX5.27/ex_5_27.sce23
-rwxr-xr-x50/CH5/EX5.29/ex_5_29.sce12
-rwxr-xr-x50/CH5/EX5.30/ex_5_30.sce18
17 files changed, 319 insertions, 0 deletions
diff --git a/50/CH5/EX5.1/ex_5_1.sce b/50/CH5/EX5.1/ex_5_1.sce
new file mode 100755
index 000000000..4ffe53138
--- /dev/null
+++ b/50/CH5/EX5.1/ex_5_1.sce
@@ -0,0 +1,12 @@
+// example: 5.1
+// linear and quadratic interpolation:
+
+// f(x)=ln x;
+
+xL=[2 2.2 2.6];
+f=[.69315 .78846 .95551];
+
+// 1) fp(2) with linear interpolation;
+
+fp=linearinterpol(xL,f);
+disp(fp);
diff --git a/50/CH5/EX5.10/ex_5_10.sce b/50/CH5/EX5.10/ex_5_10.sce
new file mode 100755
index 000000000..919949c50
--- /dev/null
+++ b/50/CH5/EX5.10/ex_5_10.sce
@@ -0,0 +1,15 @@
+// example 5.10;
+// find the jacobian matrix;
+
+
+// given two functions in x,y;
+// and the point at which the jacobian has to be found out;
+
+deff('[w]=f1(x,y)','w=x^2+y^2-x');
+
+deff('[q]=f2(x,y)','q=x^2-y^2-y');
+
+h=1;k=1;
+
+J= jacobianmat (f1,f2,h,k);
+disp(J); \ No newline at end of file
diff --git a/50/CH5/EX5.11/ex_5_11.sce b/50/CH5/EX5.11/ex_5_11.sce
new file mode 100755
index 000000000..3f861a3ea
--- /dev/null
+++ b/50/CH5/EX5.11/ex_5_11.sce
@@ -0,0 +1,18 @@
+// example : 5.11
+// solve the definite integral by 1) trapezoidal rule, 2)simpsons rule
+// exact value of the integral is ln 2= 0.693147,
+
+deff('[y]=F(x)','y=1/(1+x)')
+
+//1)trapezoidal rule,
+
+a=0;
+b=1;
+I =trapezoidal(0,1,F)
+disp(error =.75-.693147)
+
+// simpson's rule
+
+I=simpson(a,b,F)
+
+disp(error =.694444-.693147) \ No newline at end of file
diff --git a/50/CH5/EX5.12/ex_5_12.sce b/50/CH5/EX5.12/ex_5_12.sce
new file mode 100755
index 000000000..2e08e16f7
--- /dev/null
+++ b/50/CH5/EX5.12/ex_5_12.sce
@@ -0,0 +1,17 @@
+// example 5.12
+// caption: solve the integral by 1)mid-point rule,2)two-point open type rule
+
+
+// let integration of f(x)=sin(x)/(x) in the range [0,1] is equal to I1 and I2
+// 1)mid -point rule;
+a=0;b=1;
+h=(b-a)/2;
+
+x=0:h:1;
+deff('[y]=f(x)','y=sin(x)/x')
+I1=2*h*f(x(1)+h)
+
+
+//2) two-point open type rule
+h=(b-a)/3;
+I2=(3/2)*h*(f(x(1)+h)+f(x(1)+2*h)) \ No newline at end of file
diff --git a/50/CH5/EX5.13/ex_5_13.sce b/50/CH5/EX5.13/ex_5_13.sce
new file mode 100755
index 000000000..d0ada71c8
--- /dev/null
+++ b/50/CH5/EX5.13/ex_5_13.sce
@@ -0,0 +1,12 @@
+// example 5.13
+// caption: simpson 3-8 rule
+
+
+// let integration of f(x)=1/(1+x) in the range [0,1] by simpson 3-8 rule is equal to I
+
+x=0:1/3:1;
+deff('[y]=f(x)','y=1/(1+x)')
+
+[I] = simpson38(x,f)
+
+ \ No newline at end of file
diff --git a/50/CH5/EX5.15/ex_5_15.sce b/50/CH5/EX5.15/ex_5_15.sce
new file mode 100755
index 000000000..b56793e06
--- /dev/null
+++ b/50/CH5/EX5.15/ex_5_15.sce
@@ -0,0 +1,26 @@
+// example :5.15
+// find the quadrature formula of
+// integral of f(x)*(1/sqrt(x(1+x))) in the range [0,1]= a1*f(0)+a2*f(1/2)+a3*f(1)=I
+// hence find integral 1/sqrt(x-x^3) in the range [0,1]
+
+// making the method exact for polinomials of degree upto 2,
+// I=I1=a1+a2+a3
+// I=I2=(1/2)*a2+a3
+// I=I3=(1/4)*a2+a3
+
+// A=[a1 a2 a3]'
+
+I1=integrate('1/sqrt(x*(1-x))','x',0,1)
+I2=integrate('x/sqrt(x*(1-x))','x',0,1)
+I3=integrate('x^2/sqrt(x*(1-x))','x',0,1)
+
+//hence
+// [1 1 1;0 1/2 1 ;0 1/4 1]*A=[I1 I2 I3]'
+
+A=inv([1 1 1;0 1/2 1 ;0 1/4 1])*[I1 I2 I3]'
+// I=(3.14/4)*(f(0)+2*f(1/2)+f(1));
+
+// hence, for solving the integral 1/sqrt(x-x^3) in the range [0,1]=I
+
+deff('[y]=f(x)','y=1/sqrt(1+x)');
+I=(3.14/4)*[1+2*sqrt(2/3)+sqrt(2)/2] \ No newline at end of file
diff --git a/50/CH5/EX5.16/ex_5_16.sce b/50/CH5/EX5.16/ex_5_16.sce
new file mode 100755
index 000000000..f3b260f89
--- /dev/null
+++ b/50/CH5/EX5.16/ex_5_16.sce
@@ -0,0 +1,16 @@
+// example 5.16
+// caption: gauss-legendre three point method
+// I= integral 1/(1+x) in the range [0,1];
+// first we need ti transform the interval [0,1 ] to [-1,1], since gauss-legendre three point method is applicable in the range[-1,1],
+
+// let t=ax+b;
+// solving for a,b from the two ranges, we get a=2; b=-1; t=2x-1;
+
+// hence I=integral 1/(1+x) in the range [0,1]= integral 1/(t+3) in the range [-1,1];
+
+
+deff('[y]=f(t)','y=1/(t+3)');
+// since , from gauss legendre three point rule(n=2);
+I=(1/9)*(5*f(-sqrt(3/5))+8*f(0)+5*f(sqrt(3/5)))
+
+// we know , exact solution is ln 2=0.693147; \ No newline at end of file
diff --git a/50/CH5/EX5.17/ex_5_17.sce b/50/CH5/EX5.17/ex_5_17.sce
new file mode 100755
index 000000000..f0e6d0b6f
--- /dev/null
+++ b/50/CH5/EX5.17/ex_5_17.sce
@@ -0,0 +1,24 @@
+// example 5.17
+// caption: gauss-legendre method
+// I= integral 2*x/(1+x^4) in the range [1,2];
+// first we need ti transform the interval [1,2 ] to [-1,1], since gauss-legendre three point method is applicable in the range[-1,1],
+
+// let t=ax+b;
+// solving for a,b from the two ranges, we get a=1/2; b=3/2; x=(t+3)/2;
+
+// hence I=integral 2*x/(1+x^4) in the range [0,1]= integral 8*(t+3)/16+(t+3)^4 in the range [-1,1];
+
+
+deff('[y]=f(t)','y=8*(t+3)/(16+(t+3)^4) ');
+
+// 1) since , from gauss legendre one point rule;
+I1=2*f(0)
+
+// 2) since , from gauss legendre two point rule;
+I2=f(-1/sqrt(3))+f(1/sqrt(3))
+
+// 3) since , from gauss legendre three point rule;
+I=(1/9)*(5*f(-sqrt(3/5))+8*f(0)+5*f(sqrt(3/5)))
+
+
+// we know , exact solution is 0.5404; \ No newline at end of file
diff --git a/50/CH5/EX5.18/ex_5_18.sce b/50/CH5/EX5.18/ex_5_18.sce
new file mode 100755
index 000000000..08ce9df7a
--- /dev/null
+++ b/50/CH5/EX5.18/ex_5_18.sce
@@ -0,0 +1,23 @@
+// example 5.18
+// caption: gauss-chebyshev method
+
+// we write the integral as I=integral f(x)/sqrt(1-x^2) in the range [-1,1];
+// where f(x)=(1-x^2)^2*cos(x)
+
+deff('[y]=f(x)','y=(1-x^2)^2*cos(x)');
+
+// 1) since , from gauss chebyshev one point rule;
+I1=(3.14)*f(0)
+
+// 2) since , from gauss chebyshev two point rule;
+I2=(3.14/2)*f(-1/sqrt(2))+f(1/sqrt(2))
+
+// 3) since , from gauss chebyshev three point rule;
+I=(3.14/3)*(f(-sqrt(3)/2)+f(0)+f(sqrt(3)/2))
+
+
+// and 4) since , from gauss legendre three point rule;
+I=(1/9)*(5*f(-sqrt(3/5))+8*f(0)+5*f(sqrt(3/5)))
+
+
+
diff --git a/50/CH5/EX5.2/ex_5_2.sce b/50/CH5/EX5.2/ex_5_2.sce
new file mode 100755
index 000000000..cd5e0032e
--- /dev/null
+++ b/50/CH5/EX5.2/ex_5_2.sce
@@ -0,0 +1,9 @@
+// example 5.2
+// evaluate fp(.8) and fpp(.8) with quadratic interpolation;
+
+xL=[.4 .6 .8];
+f=[.0256 .1296 .4096];
+h=.2;
+
+fp=(1/2*h)*(f(1)-4*f(2)+3*f(3))
+fpp=(1/h^2)*(f(1)-2*f(2)+f(3)) // from equation 5.22c and 5.24c in the book;
diff --git a/50/CH5/EX5.20/ex_5_20.sce b/50/CH5/EX5.20/ex_5_20.sce
new file mode 100755
index 000000000..3e0f84277
--- /dev/null
+++ b/50/CH5/EX5.20/ex_5_20.sce
@@ -0,0 +1,16 @@
+// example 5.20
+// caption: gauss-leguerre method
+// I= integral e^-x/(1+x^2) in the range [0,~];
+
+// observing the integral we can inffer that f(x)=1/(1+x^2)
+
+deff('[y]=f(x)','y=1/(1+x^2) ');
+
+
+// 1) since , from gauss leguerre two point rule;
+I2=(1/4)*[(2+sqrt(2))*f(2-sqrt(2))+(2-sqrt(2))*f(2+sqrt(2))]
+
+// 3) since , from gauss leguerre three point rule;
+I=(0.71109*f(0.41577)+0.27852*f(2.29428)+0.01039*f(6.28995))
+
+
diff --git a/50/CH5/EX5.21/ex_5_21.sce b/50/CH5/EX5.21/ex_5_21.sce
new file mode 100755
index 000000000..64303a5b5
--- /dev/null
+++ b/50/CH5/EX5.21/ex_5_21.sce
@@ -0,0 +1,16 @@
+// example 5.21
+// caption: gauss-leguerre method
+// I= integral e^-x*(3*x^3-5*x+1) in the range [0,~];
+
+// observing the integral we can inffer that f(x)=(3*x^3-5*x+1)
+
+deff('[y]=f(x)','y=(3*x^3-5*x+1) ');
+
+
+// 1) since , from gauss leguerre two point rule;
+I2=(1/4)*[(2+sqrt(2))*f(2-sqrt(2))+(2-sqrt(2))*f(2+sqrt(2))]
+
+// 3) since , from gauss leguerre three point rule;
+I3=(0.71109*f(0.41577)+0.27852*f(2.29428)+0.01039*f(6.28995))
+
+
diff --git a/50/CH5/EX5.22/ex_5_22.sce b/50/CH5/EX5.22/ex_5_22.sce
new file mode 100755
index 000000000..7afdb7036
--- /dev/null
+++ b/50/CH5/EX5.22/ex_5_22.sce
@@ -0,0 +1,20 @@
+// example 5.22
+// caption: gauss-leguerre method
+// I= integral 1/(x^2+2*x+2) in the range [0,~];
+
+// since in the gauss-leguerre method the integral would be of the form e^x*f(x);
+
+// observing the integral we can inffer that f(x)=%e^x/(x^2+2*x+2)
+deff('[y]=f(x)','y=%e^x/(x^2+2*x+2) ');
+
+
+// 1) since , from gauss leguerre two point rule;
+I2=(1/4)*[(2+sqrt(2))*f(2-sqrt(2))+(2-sqrt(2))*f(2+sqrt(2))]
+
+// 3) since , from gauss leguerre three point rule;
+I=(0.71109*f(0.41577)+0.27852*f(2.29428)+0.01039*f(6.28995))
+
+
+// the exact solution is given by,
+
+I=integrate('1/((x+1)^2+1)','x',0,1000) // 1000 ~infinite;
diff --git a/50/CH5/EX5.26/ex_5_26.sce b/50/CH5/EX5.26/ex_5_26.sce
new file mode 100755
index 000000000..402f55cb0
--- /dev/null
+++ b/50/CH5/EX5.26/ex_5_26.sce
@@ -0,0 +1,42 @@
+// Example 5.26
+// caption: 1) composite trapizoidal rule, 2) composite simpsons rule with 2,4 ,8 equal sub-intervals,
+
+// I=integral 1/(1+x) in the range [0,1]
+
+deff('[y]=f(x)','y=1/(1+x)')
+
+// when N=2;
+// 1)composite trapizoidal rule
+h=1/2;
+x=0:h:1;
+
+ IT=comptrapezoidal(x,h,f)
+
+ // 2)composite simpsons rule
+
+ [I] = simpson13(x,h,f)
+
+
+ // when N=4
+ // 1)composite trapizoidal rule
+h=1/4;
+x=0:h:1;
+
+ IT=comptrapezoidal(x,h,f)
+
+ // 2)composite simpsons rule
+
+ [I] = simpson13(x,h,f)
+
+
+
+ // when N=8
+ // 1)composite trapizoidal rule
+h=1/8;
+x=0:h:1;
+
+ IT=comptrapezoidal(x,h,f)
+
+ // 2)composite simpsons rule
+
+ [I] = simpson13(x,h,f) \ No newline at end of file
diff --git a/50/CH5/EX5.27/ex_5_27.sce b/50/CH5/EX5.27/ex_5_27.sce
new file mode 100755
index 000000000..cd5800369
--- /dev/null
+++ b/50/CH5/EX5.27/ex_5_27.sce
@@ -0,0 +1,23 @@
+// example 5.27
+// caption: gauss-legendre three point method
+// I= integral 1/(1+x) in the range [0,1];
+
+// we are asked to subdivide the range into two,
+// first we need to sub-divide the interval [0,1 ] to [0,1/2] and [1/2,1] and then transform both to [-1,1], since gauss-legendre three point method is applicable in the range[-1,1],
+
+// t=4x-1 and y=4x-3;
+
+// hence I=integral 1/(1+x) in the range [0,1]= integral 1/(t+5) in the range [-1,1]+ integral 1/(t+7) in the range [-1,1]
+
+
+deff('[y1]=f1(t)','y1=1/(t+5)');
+// since , from gauss legendre three point rule(n=2);
+I1=(1/9)*(5*f1(-sqrt(3/5))+8*f1(0)+5*f1(sqrt(3/5)))
+
+deff('[y2]=f2(t)','y2=1/(t+7)');
+// since , from gauss legendre three point rule(n=2);
+I2=(1/9)*(5*f2(-sqrt(3/5))+8*f2(0)+5*f2(sqrt(3/5)))
+
+I=I1+I2
+
+// we know , exact solution is .693147; \ No newline at end of file
diff --git a/50/CH5/EX5.29/ex_5_29.sce b/50/CH5/EX5.29/ex_5_29.sce
new file mode 100755
index 000000000..7e88c2c8c
--- /dev/null
+++ b/50/CH5/EX5.29/ex_5_29.sce
@@ -0,0 +1,12 @@
+// example 5.29
+// evaluate the given double integral using the simpsons rule;
+
+// I= double integral f(x)=1/(x+y) in the range x=[1,2],y=[1,1.5];
+
+h=.5;
+k=.25;
+deff('[w]=f(x,y)','w=1/(x+y)')
+
+I=(.125/9)*[{f(1,1)+f(2,1)+f(1,1.5)+f(2,1.5)}+4*{f(1.5,1)+f(1,1.25)+f(1.5,1.5)+f(2,1.25)}+16*f(1.5,1.25)];
+disp(I);
+
diff --git a/50/CH5/EX5.30/ex_5_30.sce b/50/CH5/EX5.30/ex_5_30.sce
new file mode 100755
index 000000000..17f88a29d
--- /dev/null
+++ b/50/CH5/EX5.30/ex_5_30.sce
@@ -0,0 +1,18 @@
+// example 5.30
+// evaluate the given double integral using the simpsons rule;
+
+// I= double integral f(x)=1/(x+y) in the range x=[1,2],y=[1,2];
+// 1)
+h=.5;
+k=.5;
+deff('[w]=f(x,y)','w=1/(x+y)')
+
+I=(1/16)*[{f(1,1)+f(2,1)+f(1,2)+f(2,2)}+2*{f(1.5,1)+f(1,1.5)+f(2,1.5)+f(1.5,2)}+4*f(1.5,1.5)]
+
+// 2)
+h=.25;
+k=.25;
+deff('[w]=f(x,y)','w=1/(x+y)')
+
+I=(1/64)*[{f(1,1)+f(2,1)+f(1,2)+f(2,2)}+2*{f(5/4,1)+f(3/2,1)+f(7/4,1)+f(1,5/4)+f(1,3/2)+f(1,7/4)+f(2,5/4)+f(2,3/4)+f(2,7/4)+f(5/4,2)+f(3/2,2)+f(7/4,2)}+4*{f(5/4,5/4)+f(5/4,3/2)+f(5/4,7/4)+f(3/2,5/4)+f(3/2,3/2)+f(3/2,7/4)+f(7/4,5/4)+f(7/4,3/2)+f(7/4,7/4)}]
+