summaryrefslogtreecommitdiff
path: root/260/CH12
diff options
context:
space:
mode:
Diffstat (limited to '260/CH12')
-rw-r--r--260/CH12/EX12.1/12_1.sce39
-rw-r--r--260/CH12/EX12.2/12_2.sce36
-rw-r--r--260/CH12/EX12.3/12_3.sce25
-rw-r--r--260/CH12/EX12.4/12_4.sce37
-rw-r--r--260/CH12/EX12.5/12_5.sce15
5 files changed, 152 insertions, 0 deletions
diff --git a/260/CH12/EX12.1/12_1.sce b/260/CH12/EX12.1/12_1.sce
new file mode 100644
index 000000000..2ee6e0e88
--- /dev/null
+++ b/260/CH12/EX12.1/12_1.sce
@@ -0,0 +1,39 @@
+//Eg-12.1
+//pg-507
+
+clear
+clc
+
+x = 2.5;
+h = 0.1;
+
+deff('out = func(in)','out = in^3 -6*in^2 + 11*in -6')
+
+//Forward Difference formulas
+
+f(1) = (func(x+h) - func(x))/h;
+f(2) = (-func(x+2*h)+4*func(x+h)-3*func(x))/(2*h);
+
+//Backward Difference formulas
+
+f(3) = (func(x)-func(x-h))/h;
+f(4) = (3*func(x)-4*func(x-h)+func(x-2*h))/(2*h);
+
+//Central Difference formulas
+
+f(5) = (func(x+h)-f(x-h))/(2*h);
+f(6) = (-func(x+2*h)+8*func(x+h)-8*func(x-h)+func(x-2*h))/(12*h);
+
+
+printf('Value of derivative Type Order of error\n')
+printf(' %f Forward 1\n',f(1))
+printf(' %f Forward 2\n',f(2))
+printf(' %f Backward 1\n',f(3))
+printf(' %f Backward 2\n',f(4))
+printf(' %f Central 2\n',f(5))
+printf(' %f Central 4\n\n',f(6))
+
+printf('The exact value is -0.25\nNote that the central difference formulas provide the best estimates of the derivative\n')
+
+
+ \ No newline at end of file
diff --git a/260/CH12/EX12.2/12_2.sce b/260/CH12/EX12.2/12_2.sce
new file mode 100644
index 000000000..697eba076
--- /dev/null
+++ b/260/CH12/EX12.2/12_2.sce
@@ -0,0 +1,36 @@
+//Eg-12.2
+//pg-509
+
+clear
+clc
+
+x = 0.5;
+h = 0.1;
+
+deff('out = func(in)','out = in^2 - sin(in)')
+
+//Forward Difference formulas
+
+f(1) = (func(x+2*h) - 2*func(x+h) + func(x))/h^2;
+f(2) = (-func(x+3*h) + 4*func(x+2*h) - 5*func(x+h) + 2*func(x))/(h^2);
+
+//Backward Difference formulas
+
+f(3) = (func(x) - 2*func(x-h) + func(x-2*h))/h^2;
+f(4) = (2*func(x)-5*func(x-h)+4*func(x-2*h)-func(x-3*h))/(h^2);
+
+//Central Difference formulas
+
+f(5) = (func(x+h) - 2*func(x) + func(x-h))/(h^2);
+f(6) = (-func(x+2*h) + 16*func(x+h) - 30*func(x) + 16*func(x-h) - func(x-2*h))/(12*h^2);
+
+
+printf('Value of derivative Type Order of error\n')
+printf(' %f Forward 1\n',f(1))
+printf(' %f Forward 2\n',f(2))
+printf(' %f Backward 1\n',f(3))
+printf(' %f Backward 2\n',f(4))
+printf(' %f Central 2\n',f(5))
+printf(' %f Central 4\n\n',f(6))
+
+printf('The exact value is 2.48\nNote that for this function, several formulas in Table 12.2 provide good estimates of second derivate\n')
diff --git a/260/CH12/EX12.3/12_3.sce b/260/CH12/EX12.3/12_3.sce
new file mode 100644
index 000000000..600e8ebba
--- /dev/null
+++ b/260/CH12/EX12.3/12_3.sce
@@ -0,0 +1,25 @@
+//Eg-12.3
+//pg-511
+
+clear
+clc
+
+x = 1;
+h1 = 0.1;
+h2 = h1/2;
+
+deff('out = func(in)','out = exp(in)')
+
+//Using central difference formula
+
+Dh1 = (func(x+h1)-func(x-h1))/(2*h1);
+
+Dh2 = (func(x+h2)-func(x-h2))/(2*h2);
+
+//Using equation [16],
+
+Dnew = 4/3*Dh2 - 1/3*Dh1;
+
+printf('The value of the derivative using Richardson extrapolation is %f\n',Dnew)
+
+printf(' This value is very close to the exact value of 2.718\n') \ No newline at end of file
diff --git a/260/CH12/EX12.4/12_4.sce b/260/CH12/EX12.4/12_4.sce
new file mode 100644
index 000000000..03d55a184
--- /dev/null
+++ b/260/CH12/EX12.4/12_4.sce
@@ -0,0 +1,37 @@
+//Eg-12.4
+//pg-514
+
+clear
+clc
+
+x = 0.01;
+h1 = 0.0001;
+h2 = h1/2;
+
+Re = 10^4;
+
+deff('out = func(in)','out = 1/in^0.5 - 1.77*log(Re*in^0.5) + 0.6')
+
+//Using central difference formula
+
+Dh11 = (func(x+h1)-func(x-h1))/(2*h1);
+
+Dh21 = (func(x+h2)-func(x-h2))/(2*h2);
+
+Dh12 = (-func(x+2*h1) + 16*func(x+h1) - 30*func(x) + 16*func(x-h1) - func(x-2*h1))/(12*h1^2);
+
+Dh22 = (-func(x+2*h2) + 16*func(x+h2) - 30*func(x) + 16*func(x-h2) - func(x-2*h2))/(12*h2^2);
+
+
+
+//Using equation [16],
+
+D1new = 4/3*Dh21 - 1/3*Dh11;
+
+D2new = 4/3*Dh22 - 1/3*Dh12;
+
+printf('First Derivative = %f\n',D1new)
+printf('Second Derivative = %f\n',D2new)
+
+printf('\nAnalytically : \n')
+printf('First Derivative = -588.5\nSecond Derivative = 83850\n') \ No newline at end of file
diff --git a/260/CH12/EX12.5/12_5.sce b/260/CH12/EX12.5/12_5.sce
new file mode 100644
index 000000000..061f330be
--- /dev/null
+++ b/260/CH12/EX12.5/12_5.sce
@@ -0,0 +1,15 @@
+//Eg-12.5
+//pg-515
+
+clear
+clc
+
+x = [0;0.5;1.2];
+T = [450;388;325];
+
+//The derivative can be computed using the equation [19]
+//Therefore the derivative at x = 1
+
+D = ((2-0.5-1.2)/((0-0.5)*(0-1.2)))*450 + ((2-0-1.2)/((0.5-0)*(0.5-1.2)))*388 + ((2-0-0.5)/((1.2-0)*(1.2-0.5)))*325;
+
+printf('The value of derivative at x = 1 is %f',D)