Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: rookie Q, visualize function with 3 variables

Subject: rookie Q, visualize function with 3 variables

From: Bo Pan

Date: 22 Nov, 2007 01:46:50

Message: 1 of 3

hi
i've got a function in the form of

x^2 + 6xy - 2y^2 - 2yz + z^2 = 24

how can i visualize this function in matlab?

thanks

Subject: Re: rookie Q, visualize function with 3 variables

From: Roger Stafford

Date: 22 Nov, 2007 07:48:06

Message: 2 of 3

"Bo Pan" <ppyzbp@nottingham.ac.uk> wrote in message <fi2n2a$1nt
$1@fred.mathworks.com>...
> hi
> i've got a function in the form of
>
> x^2 + 6xy - 2y^2 - 2yz + z^2 = 24
>
> how can i visualize this function in matlab?
>
> thanks
--------
  Perhaps it would help in visualizing this to know that the surface defined by
your equation is that of a one-sheeted hyperboloid. However its principal
axes are not aligned with your x,y,z coordinate axes. You can determine
what these principal axes are as follows.

  From the coefficients in the quadratic expression define the matrix

 e = [ 1 , 6/2 , 0/2;
       6/2 , -2 , -2/2;
       0/2 , -2/2 , 1 ];

That is, the coefficients of x^2, y^2, and z^2 are its diagonal elements and
half those of x*y, y*z, and x*z (which isn’t there in this case) are its
symmetrical off-diagonals.

  Then find the eigenvectors and eigenvalues of e.

 [v,d] = eig(e);

 v =
   0.80178372573727 -0.31622776601684 0.50709255283711
   0.53452248382485 -0.00000000000000 -0.84515425472852
  -0.26726124191242 -0.94868329805051 -0.16903085094570

 diag(d) =
   3.00000000000000
   1.00000000000000
  -4.00000000000000

The columns of v are the eigenvectors and they constitute the three principal
directions of the hyperboloid. The diagonals of d are the eigenvalues (and in
this case are all integers.)

  You then define a transformed (rotated) coordinate system (X,Y,Z) in terms
of these eigenvectors.

 X = v(1,1)*x+v(2,1)*y+v(3,1)*z;
 Y = v(1,2)*x+v(2,2)*y+v(3,2)*z;
 Z = v(1,3)*x+v(2,3)*y+v(3,3)*z;

The X, Y, and Z axes point in the direction of the hyperboloid’s principal axes
and we have the identity

 d(1,1)*X^2+d(2,2)*Y^2+d(3,3)*Z^2 =
 3*X^2+1*Y^2+(-4)*Z^2 =
 x^2+6*x*y-2*y^2-2*y*z+z^2 = 24

or

 X^2/8 + Y^2/24 - Z^2/6 = 1

  This makes it evident that we are dealing with a one-sheeted hyperboloid
with the above principal directions. Every cross section orthogonal to the Z
axis - that is, having a constant value of Z - will be an X,Y ellipse:

 X^2/8 + Y^2/24 = 1 + Z^2/6

Similarly, every cross section containing the Z-axis will be a hyperbola.

  Presumably you can now use the new transformed X,Y,Z coordinates to
generate a surface which matlab can display using a function like 'surf'.

Roger Stafford

Subject: Re: rookie Q, visualize function with 3 variables

From: Roger Stafford

Date: 22 Nov, 2007 17:37:28

Message: 3 of 3

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fi3c7m$a7d$1@fred.mathworks.com>...
> .......
> You then define a transformed (rotated) coordinate system (X,Y,Z) in
terms
> of these eigenvectors.
>
> X = v(1,1)*x+v(2,1)*y+v(3,1)*z;
> Y = v(1,2)*x+v(2,2)*y+v(3,2)*z;
> Z = v(1,3)*x+v(2,3)*y+v(3,3)*z;
>
> The X, Y, and Z axes point in the direction of the hyperboloid's principal
axes
> and we have the identity
>
> d(1,1)*X^2+d(2,2)*Y^2+d(3,3)*Z^2 =
> 3*X^2+1*Y^2+(-4)*Z^2 =
> x^2+6*x*y-2*y^2-2*y*z+z^2 = 24
>
> or
>
> X^2/8 + Y^2/24 - Z^2/6 = 1
> .......
  I didn't explain the "identity" in the above paragraph very well. I should have
said that, since e is symmetric, we have e = v*d*v' and therefore

24 = x^2+6*x*y-2*y^2-2*y*z+z^2 = [x,y,z]*e*[x;y;z]
= [x,y,z]*v*d*v’*[x;y;z] = [X,Y,Z]*d*[X;Y;Z]
= 3*X^2+Y^2-4*Z^2

which is equivalent to

X^2/8 + Y^2/24 - Z^2/6 = 1

Roger Stafford

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics