0% found this document useful (0 votes)
8 views

Assignment Group 2

The document discusses solving several optimization problems using techniques like finding relative maxima, using differentials to approximate values, finding equations of tangent planes, computing volumes of intersections between geometric objects, and using numerical methods like bisection and fixed point iteration to find solutions to equations.

Uploaded by

siamiso2410
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Assignment Group 2

The document discusses solving several optimization problems using techniques like finding relative maxima, using differentials to approximate values, finding equations of tangent planes, computing volumes of intersections between geometric objects, and using numerical methods like bisection and fixed point iteration to find solutions to equations.

Uploaded by

siamiso2410
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Q.

NO-01
2
-y 2
Find all relative maxima of the function f(x,y) = xye -x sketch the surface.
n
Sol :

In[ ]:= f[x_, y_] = x y Exp- x2 - y2 ;


pdx = ∂x f[x, y] // Factor
2
-y2
Out[ ]= - -x - 1 + 2 x2  y

In[ ]:= pdy = ∂y f[x, y] // Factor


2
-y2
Out[ ]= - -x x - 1 + 2 y2 

If we try to use Solve to find where the partial derivatives are 0. We will get an error message due to
2
-y 2
the presence of the (non -algebraic ) exponential .However ,since -e -x cannot equal zero , we
can ignore its presence .

In[ ]:= Solve1 + 2 x2  y  0, x - 1 + 2 y2   0, {x, y}


 1  1
Out[ ]= x  - ,y- , x  - ,y ,
2 2 2 2
 1  1
x  ,y- , x  ,y , {x  0, y  0}
2 2 2 2

2
In[ ]:= d[x_, y_] = ∂{x,2} f[x, y] × ∂{y,2} f[x, y] - ∂{x,y} f[x, y] ;
d[0, 0]
Out[ ]= 0

1 1
In[ ]:= ∂{x,2} f[x, y] /. x  ,y 
Sqrt[2] Sqrt[2]
2
Out[ ]= -

1 1
Relative maximum at ( , ).
2 2

1 -1
In[ ]:= ∂{x,2} f[x, y] /. x  ,y 
Sqrt[2] Sqrt[2]
2
Out[ ]=

2 assignment,,,.nb

In[ ]:= Plot3D[f[x, y], {x, - 3, 3}, {y, - 3, 3}, PlotPoints  30,
ViewPoint  {1.391, - 3.001, 0.713}, PlotRange  All]
Plot3D[f[x, y], {x, - 3, 3}, {y, - 3, 3}, PlotPoints  30,
ViewPoint  {0.617, - 3.318, 0.245}, PlotRange  All]

Out[ ]=

Out[ ]=

Q.NO-02
Use differentials to approximate e0.1 4.010020 and determine the percentage error of the estimate
.

Soln :
We take advantage of the fact that 0.1 is near 0 and 4.010020 is near 4.
In[ ]:= f[x_, y_] = Exp[x] Sqrt[y];
approximation = f[0, 4] + Dt[f[x, y]] /. {x  0, y  4, Dt[x]  0.1, Dt[y]  0.010020}
Out[ ]= 2.20251

In[ ]:= exactvalue = f[0.1, 4.010020]


Out[ ]= 2.21311

In[ ]:= percenerror = Abs[approximation - exactvalue] / exactvalue * 100;


Print["The error is ", percenerror , "%"]
The error is 0.479125%
assignment,,,.nb 3

Q.NO-03
Find an equation of the tangent plane to the surface x 2 y- 4 z2 = -7 at the point (-3,1,2).Sketch the
surface and its tangent plane.
Soln :

In[ ]:= f[x_, y_, z_] = x2 y - 4 z2 + 7;


a = Derivative[1, 0, 0][f][- 3, 1, 2];
b = Derivative[0, 1, 0][f][- 3, 1, 2];
c = Derivative[0, 0, 1][f][- 3, 1, 2];
Solve[a (x + 3) + b (y - 1) + c (z - 2)  0, z]
1
Out[ ]= z  (5 - 6 x + 9 y)
16

This is the equation of tangent plane.

In[ ]:= g1 = Plot3D x2 y + 7  4 , {x, - 5, 5}, {y, - 5, 5};


1
g2 = Plot3D (5 - 6 x + 9 y), {x, - 5, 5}, {y, - 5, 5};
16
Show[g1, g2]

Out[ ]=

Q.NO-04
Find the points on the sphere x 2 +y 2 +z2 =36 that are closest to and farthest from the point
(1,2,2).
Soln :
The sphere’s equation is x 2 + y 2 + z2 =36
4 assignment,,,.nb

In[ ]:= f[x_, y_, z_] = (x - 1)2 + (y - 2)2 + (z - 2)2 ;


g[x_, y_, z_] = x2 + y2 + z2 - 36;
conditions = Eliminate∂x f[x, y, z]  λ ∂x g[x, y, z],
∂y f[x, y, z]  λ ∂y g[x, y, z], ∂z f[x, y, z]  λ ∂z g[x, y, z], g[x, y, z]  0, λ

Out[ ]= 2 x  z && y  z && z2  16

In[ ]:= points = Solve[conditions, {x, y, z}]


Out[ ]= {{x  - 2, y  - 4, z  - 4}, {x  2, y  4, z  4}}

In[ ]:= f[x, y, z] /. points // N


Out[ ]= {9., 3.}

The farthest points closest to are (2,4,4) and farthest to are (-2,-4,-4).

Q.NO-05
A silo is formed above the x - y plane by the intersection of a right circular cylinder of radius 3
and a sphere of radius 5. Compute its volume.
Soln :
The equation of the spherical cap is 25 - r 2 . It will intersect the cylinder when r =
3. The height of the cylinder will be 4.
In[ ]:= cylinder = Graphics3D[Cylinder[{{0, 0, 0}, {0, 0, 4}}, 3]];
cap = RevolutionPlot3D 25 - r2 , {r, 0, 3}, {θ, 0, 2 π};
Show[cylinder, cap, Boxed  False, PlotRange  {0, 5}]

Out[ ]=

2π 3 25-r2
In[ ]:= volume =    r z r θ
0 0 0
122 π
Out[ ]=
3
assignment,,,.nb 5

Q.NO-06
Use the bisection method to find solution accurate to within 10-2 for x 4 - 2 x 3 - 4 x 2 + 4x + 4=0 on
the interval [0,2].
Soln :

In[ ]:= f[x_] := x4 - 2 * x3 - 4 * x2 + 4 * x + 4


Plot[f[x], {x, - 1, 3}]
solution = FindRoot[f[x]  0, {x, 1.5}];
exact = solution〚1, 2〛;
(Label[1];
a = 0;
b = 2;
If[f[a] * f[b] > 0,
{Print["Enter a and b such that f[a] and f[b] have opposite sign"];
Goto[1];}];);
n = 20;
tol = 10-2 ;
k = 0;
For[i = 1, i ≤ n, i ++, {x0[i] = a; x1[i] = b; c = (a + b) / 2; x2[i] = c; k ++;
If[Abs[a - b] ≤ tol, Break[];, If[f[c] * f[a] > 0, a = c, b = c];]}];
t = Table[{i, x0[i], x1[i], x2[i], f[x2[i]], Abs[exact - x2[i]]}, {i, 1, k}];
PaddedForm[
TableForm[t, TableHeadings  {None, {"iteration", "a", "b", "c", "f(c)", "Error"}},
TableAlignments  Center] // N, {5, 8}]
If[k  n, Print["Maximum number of iteration exceeded"]];

2
Out[ ]=

-1 1 2 3

-2

-4

Out[ ]//PaddedForm=

iteration a b c f(c) Error


1.00000000 0.00000000 2.00000000 1.00000000 3.00000000 0.41421000
2.00000000 1.00000000 2.00000000 1.50000000 -0.68750000 0.08578600
3.00000000 1.00000000 1.50000000 1.25000000 1.28520000 0.16421000
4.00000000 1.25000000 1.50000000 1.37500000 0.31274000 0.03921400
5.00000000 1.37500000 1.50000000 1.43750000 -0.18651000 0.02328600
6.00000000 1.37500000 1.43750000 1.40630000 0.06367600 0.00796360
7.00000000 1.40630000 1.43750000 1.42190000 -0.06131800 0.00766140
8.00000000 1.40630000 1.42190000 1.41410000 0.00120850 0.00015106
9.00000000 1.41410000 1.42190000 1.41800000 -0.03004800 0.00375520
6 assignment,,,.nb

Q.NO-07
Use the Fixed point iteration method to find solution accurate to within 10-4 for x 3 + x 2 -1 = 0 on the
interval [0,1].
Soln :

In[ ]:= g[x_] := 1  1+x


Plot[{g[x], x}, {x, 0, 1}, PlotRange  {0, 1}]
initialGuess = 0.5;
maxIteration = 50;
tol = 10-4 ;

For[k = 1, k ≤ maxIteration, k ++,


x[k] = initialGuess;
f[k] = g[x[k]];
err[k] = Abs[f[k] - x[k]];
initialGuess = f[k];
If[err[k] ≤ tol, sol = x[k]; Break[]]
]

TableForm[Table[{i, x[i], err[i]}, {i, 1, k}],


TableHeadings  {None, {"Iteration", "Approximation", "Error"}}]
If[k > maxIteration, Print["Solution not found. Max iteration exceeded."],
Print["The solution is ", sol]]

1.0

0.8

0.6

Out[ ]=

0.4

0.2

0.0 0.2 0.4 0.6 0.8 1.0

Out[ ]//TableForm=
Iteration Approximation Error
1 0.5 0.316497
2 0.816497 0.0745328
3 0.741964 0.0157068
4 0.757671 0.00339293
5 0.754278 0.000729068
6 0.755007 0.000156839
7 0.75485 0.0000337315

The solution is 0.75485


assignment,,,.nb 7

Q.NO-08
Find a real root of the equation x 3 + x 2 -1 =0 on the interval [0,1] by using False position method
correct up to six decimal places.
Soln :

In[ ]:= f[x_] := x3 + x2 - 1;


Plot[f[x], {x, 0, 1}]
tol = 10-6 ;
maxIteration = 50;
x1 = 0;
x2 = 1;

Fork = 1, k ≤ maxIteration, k ++,


fa = f[x1] // N;
fb = f[x2] // N;
fb * (x2 - x1)
c[k] = x2 - // N;
(fb - fa)
fc = f[c[k]] // N;
a[k] = x1;
b[k] = x2;
err[k] = Abs[fc];
If[fa * fc < 0, x2 = c[k], x1 = c[k]];
If[err[k] ≤ tol, sol = c[k]; Break[]]

TableForm[Table[{i, a[i], b[i], c[i], err[i]}, {i, 1, k}],


TableHeadings  {None, {"Iteration", "a", "b", "c", "error"}},
TableAlignments  Center]

If[k > maxIteration, Print["Solution not found. Max iteration exceeded."],


Print["The solution is ", sol]]
1.0

0.5

Out[ ]=
0.2 0.4 0.6 0.8 1.0

-0.5

-1.0
8 assignment,,,.nb

Out[ ]//TableForm=
Iteration a b c error
1 0 1 0.5 0.625
2 0.5 1 0.692308 0.188894
3 0.692308 1 0.741194 0.0434413
4 0.741194 1 0.751969 0.00933539
5 0.751969 1 0.754263 0.00197657
6 0.754263 1 0.754748 0.000417179
7 0.754748 1 0.75485 0.0000879919
8 0.75485 1 0.754872 0.0000185567
9 0.754872 1 0.754876 3.91334 × 10-6
10 0.754876 1 0.754877 8.25261 × 10-7
The solution is 0.754877

Q.NO-09
Find a real root of the equation x 3 + x 2 -1 =0 on the interval [0,1] by using Newton Raphson method
correct up to six decimal places.
Soln :
assignment,,,.nb 9

In[ ]:= f[x_] := x3 + x2 - 1;


Plot[f[x], {x, - 2, 2}]

Label[1];

0+1
x0 = ;
2
If[Abs[f '[x0]]  0, {Print["Re-enter a suitable initial point"];

Goto[1];}] ;

sol = FindRoot[f[x]  0, {x, x0}];


exact = sol〚1, 2〛;
a[0] = x0;
n = 50;
tol = 10-7 ;
f[x0]
Fori = 1, i ≤ n, i ++, x = x0 - ;
f '[x0]
a[i] = x; If[Abs[x - x0] < tol, Break[]]; x0 = x;;
t = Table[{k, a[k], Abs[exact - a[k]]}, {k, 0, i}];
tf = TableForm[t, TableHeadings  {None, {"Iteration", "Approximation", "Error"}},
TableAlignments  Center];
PaddedForm[tf // N, {12, 10}]
If[i  n, Print["Maximun number of iteration exceeded"]];

10

Out[ ]=

-2 -1 1 2

-5

Out[ ]//PaddedForm=

Iteration Approximation Error


0.0000000000 0.5000000000 0.2548776662
1.0000000000 0.8571428571 0.1022651909
2.0000000000 0.7641369048 0.0092592385
3.0000000000 0.7549634824 0.0000858161
4.0000000000 0.7548776737 7.4672622530 × 10-9
5.0000000000 0.7548776662 0.0000000000

The solution is 0.7548776662.

Q.NO-10
Use Runge method of order four to approximate the solution of the initial value proble-
m y ′ = t 3 t -2y , y(0)=0 , which h=0.2 and compare it with the actual values of y.
10 assignment,,,.nb

Soln :

In[ ]:= sol = DSolveValuey '[t]  t 3 t - 2 y[t], y[0]  0, y[t], t


1
Out[ ]= -2 t 1 - 5 t + 5 5 t t
25

In[ ]:= f[t_, y_] := t 3 t - 2 y


tl = 0; tr = 1; y0 = 0; n = 10;
h = 0.2;
ta[0] = 0; ya[0] = 0;
For[i = 1, i ≤ n, i ++, {k1 = h * f[ta[i - 1], ya[i - 1]];
k2 = h * f[ta[i - 1] + h / 2, ya[i - 1] + k1 / 2];
k3 = h * f[ta[i - 1] + h / 2, ya[i - 1] + k2 / 2];
k4 = h * f[ta[i - 1] + h, ya[i - 1] + k3];
ta[i] = ta[0] + i * h;
ya[i] = ya[i - 1] + (k1 + 2 k2 + 2 k3 + k4) / 6;}];
s = Table[
{ta[i], exact = sol /. {t  ta[i]}, ya[i], error = Abs[ya[i] - exact]}, {i, 0, n}];
PaddedForm[
TableForm[s, TableHeadings  {None, {"t", "Exact", "Approximation", "Error"}},
TableAlignments  Center] // N, {12, 6}]
Out[ ]//PaddedForm=
t Exact Approximation Error
0.000000 0.000000 0.000000 0.000000
0.200000 0.026813 0.026906 0.000093
0.400000 0.150778 0.151047 0.000269
0.600000 0.496020 0.496648 0.000628
0.800000 1.330857 1.332228 0.001371
1.000000 3.219099 3.221993 0.002893
1.200000 7.323276 7.329260 0.005984
1.400000 16.007152 16.019348 0.012197
1.600000 34.024547 34.049123 0.024576
1.800000 70.851146 70.900211 0.049065
2.000000 145.235098 145.332308 0.097209

Q.NO-11
6
Evaluate ∫0 1 1 + x 2   x by using (a) Trapezoidal rule (b) Simpson’s 1/3 rule (c) Simpson’s 3/8 rule
and compare it with the actual values.
Soln :

Trapezoidal Rule
assignment,,,.nb 11

In[ ]:= f[x_] := 1  1 + x2 ;


a = 0;
b = 6;
b
exact =  f[x]  x;
a
n = 6;
h = (b - a) / n;
sum1 = f[a] + f[b];
sum2 = 0;
For[i = 1, i ≤ n - 1, i ++, sum2 = sum2 + 2 * f[a + i * h]]
trapezoidal = h * (sum1 + sum2) / 2;
error = Abs[exact - trapezoidal];
Print["Result from Trapezoidal rule=", PaddedForm[trapezoidal // N, {15, 12}]];
Print["Result from exact=", PaddedForm[exact // N, {15, 14}]];
Print["Error=", PaddedForm[error // N, {15, 14}]];

Result from Trapezoidal rule= 1.410798581387

Result from exact= 1.40564764938027

Error= 0.00515093200655

Simpson’s 1/3 rule


In[ ]:= f[x_] := 1  1 + x2 ;
a = 0;
b = 6;
b
exact =  f[x]  x;
a
n = 6;
h = (b - a) / n;
sum1 = 0;
sum2 = 0;
sum3 = 0;
sum1 = f[a] + f[b];
For[i = 1, i ≤ n - 1, i ++,
If[Mod[i, 2]  0, sum2 = sum2 + 2 * f[a + i * h], sum3 = sum3 + 4 * f[a + i * h]]];
s13 = h * (sum1 + sum2 + sum3) / 3;
error = Abs[exact - s13];
Print["Result from Simpon's 1/3=", PaddedForm[s13 // N, {15, 14}]];
Print["Result from exact=", PaddedForm[exact // N, {15, 14}]];
Print["Error=", PaddedForm[error // N, {15, 14}]];

Result from Simpon's 1/3= 1.36617341323224

Result from exact= 1.40564764938027

Error= 0.03947423614803

Simpson’s 3/8 rule


12 assignment,,,.nb

In[ ]:= f[x_] := 1  1 + x2 ;


a = 0;
b = 6;
b
exact =  f[x]  x;
a
n = 6;
h = (b - a) / n;
sum1 = 0;
sum2 = 0;
sum3 = 0;
sum1 = f[a] + f[b];
For[i = 1, i ≤ n - 1, i ++,
If[Mod[i, 3]  0, sum2 = sum2 + 2 * f[a + i * h], sum3 = sum3 + 3 * f[a + i * h]]];
s38 = 3 * h * (sum1 + sum2 + sum3) / 8;
error = Abs[exact - s38];
Print["Result from Simpon's 3/8=", PaddedForm[s38 // N, {15, 14}]];
Print["Result from exact=", PaddedForm[exact // N, {15, 14}]];
Print["Error=", PaddedForm[error // N, {15, 14}]];

Result from Simpon's 3/8= 1.35708083649260

Result from exact= 1.40564764938027

Error= 0.04856681288767

Q.NO-12
Use Gaussian elimination with backward substitution to solve the following linear system x-y+3z=2,
3x-3y+z =1 , x+y = 3.
assignment,,,.nb 13

In[ ]:= n = Input["Enter the number of equation"];


For[i = 1, i ≤ n, i ++,
For[j = 1, j ≤ n + 1, j ++,
a[i, j] = Input["Enter the Coeffieient Matrix"];]]
TableForm[Table[a[i, j], {i, 1, n}, {j, 1, n + 1}]]

For[i = 1, i ≤ n - 1, i ++ {p = i;
For[j = i, j ≤ n, j ++, If[a[j, i] ≠ 0, {p = j;
Break[];}]];
If[a[p, i]  0, {Print["No uniqe Solution"];
Exit[];}];
If[p ≠ i, For[k = 1, k ≤ n + 1, k ++, {t = a[i, k];
a[i, k] = a[p, k];
a[p, k] = t;}];];
For[j = i + 1, j ≤ n, j ++, {m[j, i] = a[j, i] / a[i, i];
For[k = 1, k ≤ n + 1, k ++,
a[j, k] = a[j, k] - m[j, i] * a[i, k]];}];}];
If[a[n, n]  0, {Print["No unique solution"];
Exit[];}];
x[n] = a[n, n + 1] / a[n, n];
n
Fori = n - 1, i ≥ 1, i --, x[i] = a[i, n + 1] -  a[i, k] * x[k]  a[i, j];;
k=i+1

Table[x[i], {i, 1, n}]


Out[ ]//TableForm=
1 -1 3 2
3 -3 1 -1
1 1 0 3

13
Out[ ]= - , 9, 8
2

You might also like