themysteryofnature.files.wordpress.com · web viewmatlab 3d plotting and finding stationary points...

15
Matlab 3D Plotting and Finding Stationary Points of a Surface Locate the stationary points of the function f(x,y) = (x 2 – 2y 2 )exp[-(x 2 + y 2 )/a 2 ] where a is a non-zero constant. (Riley,Hobson and Bence, ‘Mathematical Methods for physics and engineering’, 3 rd Edition, Pg-181, Ex – 5.13) Solution In the abobe question we try to find the maxima, minima and saddle points in the surface described by the above mentioned function. This question is related to finding the stationary points of a given surface (3 dimensional) using partial derivatives. Here I have tried to go through all the mathematical details and also use matlab to graph the surface and view if our mathematically calculated stationary points exactly lie on intended positions in the real surface. So, this question is actually about how matlab can be useful in visualizing mathematical ideas that is difficult to do using paper and pencil. First of all I will go through the matematical part of the above question. If you don’t have an idea of partial dervatives you may skip this part or see only the conclusion part. We use partial derivative to determine the stationary points of any surface described by a function with two independent variables (here x and y). Condition for any points to be stationary is that its first derivatives must be zero. Remember, stationary points contain

Upload: others

Post on 02-Feb-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Matlab 3D Plotting and Finding Stationary Points of a Surface

Locate the stationary points of the function

f(x,y) = (x2 – 2y2)exp[-(x2 + y2)/a2] where a is a non-zero constant.

(Riley,Hobson and Bence, ‘Mathematical Methods for physics and engineering’, 3rd Edition, Pg-181, Ex – 5.13)

Solution

In the abobe question we try to find the maxima, minima and saddle points in the surface described by the above mentioned function. This question is related to finding the stationary points of a given surface (3 dimensional) using partial derivatives. Here I have tried to go through all the mathematical details and also use matlab to graph the surface and view if our mathematically calculated stationary points exactly lie on intended positions in the real surface. So, this question is actually about how matlab can be useful in visualizing mathematical ideas that is difficult to do using paper and pencil. First of all I will go through the matematical part of the above question. If you don’t have an idea of partial dervatives you may skip this part or see only the conclusion part.

We use partial derivative to determine the stationary points of any surface described by a function with two independent variables (here x and y). Condition for any points to be stationary is that its first derivatives must be zero. Remember, stationary points contain maxima, minima as well as saddle points. Hence, for any point to be stationary it is necessary that

, , Somewhere it is also represented as fx = 0 ; fy = 0. I will use latter one.

After we find this, we determine whether the given points are maxima, minima or saddle points based on the following conditions:

i) Minima if both , i.e. second partial derivative with respect to both the independent variable are positive. And also ) . Second partial derivative with respect to x is also written as fxx . Similarly for y and both x an y. So, above condition may also be written as fxx > 0, fyy > 0 and (fxy)2 < (fxx) (fyy).

ii) Maxima if both , i.e. second partial derivative with respect to both the independent variable are negative. And also ). So, above condition may also be written as fxx < 0, fyy < 0 and (fxy)2 < (fxx) (fyy).

iii) Saddle points if fxx and fyy have opposite signs OR (fxy)2 > (fxx) (fyy).

We have f(x,y) = (x2 – 2y2)exp[-(x2 + y2)/a2]

Now I calculated fx = exp [ ] (2x - 2 + ) which may also be written as

fx = 2x exp [ ] (1 - + ) …………(1)

Similarly I calculated

fy = exp [ ] ( - 4y + 4) which may also be written as

fy = 2y exp [ ] ( - 2 + 2) ……………(2)

Second partial derivatives of the given function were calculated as follows

fxx = exp [ ] ( + 44 - 8 ) …….(3)

fyy = exp [ ] ( - 4 + 12 +8 - 8 ) …….(4)

Similarly fxy was calculated to be

fxy = = exp [ ] ( + + 8 - 8 ) ………..(5)

Having found all the required partial derivatives now we try to find out the stationary poins using the condition fx = 0 and fy = 0.

fx = 2x exp [ ] (1 - + ) = 0

which gives, x = 0 and 1 - + = 0 2nd expression on simplification gives

x2 = a2 + 2y2 I did not find x and instead ketp the value of x2 because latter it will be easier for calculation. So, we have

x = 0 ……..(6)

x2 = a2 + 2y2 ……..(7)

Similarly calculating for fy = 0 ; fy = 2y exp [ ] ( - 2 + 2) = 0 we get,

y = 0 ………..(8)

y2 = ……..(9)

Now we solve these equations (6), (7), (8) and (9) to get (x,y).

Put x = 0 in (9) we get y = +/- a. Again put y = 0 in (7) we get x = +/- a. So our set of stationary points are:

(x,y) = (0,0), (a,0), (-a,0), (0,a), (0,-a) or in more compact form

(x,y) = (0,0), (+/- a, 0), (0,+/-a)

Case 1

Take point (+/- a, 0). Substitute x =a and y = 0 in

fxx = exp [ ] ( + 44 - 8 )

we get

fxx at (a, 0)

fxx = exp [ ] ( + 44 - 8 )

= exp(-1) (2 – 10 + 0 + 4 - 0)

= -4 exp(-1)

= - ve quantity

Similarly substitute (a, 0) in fyy

fyy = exp [ ] ( - 4 + 12 +8 - 8 ) we get,

fyy = exp [ ] ( - 4 + 12 +8 - 8 )

= exp(-1) (-2 – 4 + 0 + 0 + 0 + 0)

= -6 exp(-1)

= - ve quantity

Similarly, substitute (a,0) in fxy

fxy = = exp [ ] ( + + 8 - 8 ) we get

fxy = 0

Now, fxx fyy = -4exp(-1) -6exp(-2) = 24 exp(-1). Also (fxy )2 = 0. So, we have fxx fyy > fxy.

Here we see that the point (a,0) satisfies all the required conditions to be a maximum point.

i) fxx < 0, fyy < 0 and fxx fyy > fxy

Hence, (a,0) is a point of maxima. Similarly one may check that (-a, 0) also meets all the required conditions for maxima making it another point of maxima.

Maxima at (+/-a, 0)

Case 2

Take point (0, +/-a) and substitute in fxx and fyy

fxx = exp [ ] ( + 44 - 8 )

= exp [ ] ( + 44 - 8 )

= exp(-1) (2 – 0 + 4 + 0 - 0)

= 6 exp(-1)

= +ve quantity

fyy = exp [ ] ( - 4 + 12 +8 - 8 )

= exp [ ] ( - 4 + 12 +8 - 8 )

= exp(-1) (0 -4 + 12 + 0 + 8 - 8)

= 8 exp(-1)

= +ve quantity

fxy = exp [ ] ( + + 8 - 8 )

= exp(-1) (0)

= 0

fxx fyy = 6exp(-1) 8exp(-1) = 48 exp(-2)

So, fxx fyy > (fxy)2

We see that point (0,+/-a) satisfies the required conditions of minima. Hence there lies minima at point (0,+/-a).

Minima at point (0,+/-a).

Case 3

Take point (0,0) and substitute at fxx and fyy

fxx = exp [ ] ( + 44 - 8 )

fxx = exp [ ] ( + 44 - 8 )

fxx= 2

fyy = exp [ ] ( - 4 + 12 +8 - 8 )

= exp [ ] ( - 4 + 12 +8 - 8 )

= - 4

So we see that fxx and fyy have opposite sign – a condition for a point to be a saddle point.

Saddle point at (0,0)

From our mathematical theory we have found that for a surface described by a function

f(x,y) = (x2 – 2y2)exp[-(x2 + y2)/a2]

we have maximum points at (a,0) and (-a,0), minimum points at (0,a) and (0,-a) and saddle point at (0,0). What we see is that the maxima, minima and saddle points depend are determined by the value of the arbitrary positive constant a. Let us assume a = 2 to visualize above problem using matlab. Mathematically we got this result and we want to see how does a surface described by above function look like and also to check if these points really do represent the points of maxima, minima and saddle. For this we use matlab’s 3D plotting function.

NOTE: Actually video tutorial would have been more interactive and better to visualize and undestand all these topics but due to my limitations (like I don’t have camera and all those stuffs) I am unable to do video tutorial. However I will try to do my best here.

MATLAB PART

Firstly let us see how does a 3D graph of above function looks like. Those of you who have acess to matlab may try the code below (red colored part) and see for yourself.

Code Block

X = [-5:0.1:5];

Y = [-5:0.1:5];

[x,y] = meshgrid(X,Y);

z = (x.^2 - 2*(y.^2)).*exp(-(x.^2 + y.^2)/4);

mesh(x,y,z),xlabel('x-axis'),ylabel('y-axis'),zlabel('z-axis'),

Remember that we have assumed the value of the constant ‘a’ in the function to be 2. Using matlab we get the graph of the above function as shown below.

Figure: Graph of function f(x,y) = (x2 – 2y2)exp[-(x2 + y2)/a2]

Figure: Above graph as it looks when viewed from below.

Figure: Same figure viewed with box in it.

Note: The code given above produces only the graph shown in the first figure but the remaining two figures are different orientation of the same figure which can be viewed using matlab tools. I could have showed that if this was a video tutorial but for now lets be happy with this.

Now lets us plot our maxima, minima and saddle points and see if the lie on the corresponding regions in the graph.

First let me plot the point of maximum which is (2,0) and (-2,0) as we have assumed a = 2. Try the code below to see urself how does it look like.

Code Block

X = [-5:0.1:5];

Y = [-5:0.1:5];

[x,y] = meshgrid(X,Y);

z = (x.^2 - 2*(y.^2)).*exp(-(x.^2 + y.^2)/4);

mesh(x,y,z),xlabel('x-axis'),ylabel('y-axis'),zlabel('z-axis'),

hold on

x = 2; % This is our maximum point at x = 2

y = 0; % This is our maximum point at y = 0

z = (x.^2 – 2*(y.^2)).*exp(-(x.^2 + y.^2)/4);

plot3(x,y,z,'k.','MarkerSize',30)

x = -2; % This is our maximum point at x = -2

y = 0; % This is our maximum point at y = 0

z = (x.^2 - 2*(y.^2)).*exp(-(x.^2 + y.^2)/4);

plot3(x,y,z,'k.','MarkerSize',30)

Above code gives us figure as shown below and black dot in the figure indicates the point of maxima.

I gues everyone can easily see two black dots at the upper two bumbs. X and Y axes do not appear in the figure because they were lost as I wanted to zoom the region of maxima so that our points of maima could be viwed clearly. What we see is our mathematically calculated values exactly lies at the same place where it should be in the figure. The zeniths of the upper two bumps are the maxima of this surface. Similarly lets us view the points of minima.

One may try the code below.

Code Block

X = [-5:0.1:5];

Y = [-5:0.1:5];

[x,y] = meshgrid(X,Y);

z = (x.^2 - 2*(y.^2)).*exp(-(x.^2 + y.^2)/4);

mesh(x,y,z),xlabel('x-axis'),ylabel('y-axis'),zlabel('z-axis'),

hold on

x = 0;

y = 2;

z = (x.^2 - 2*(y.^2)).*exp(-(x.^2 + y.^2)/4);

plot3(x,y,z,'k.','MarkerSize',30)

x = 0;

y = -2;

z = (x.^2 - 2*(y.^2)).*exp(-(x.^2 + y.^2)/4);

plot3(x,y,z,'k.','MarkerSize',30)

In the figure shown below we can see two black dot representing the points (0,2) and (0,-2) lying exactly at the desired place. Tip of the lower two bumps are the point of minima and we see our points exactly lie on those places.

Figure: Display of points of minima

Same figure above shown from below with a zoomed view. Two black dots represent the points of minima.