supusr
supusr

Reputation: 3

How to obtain a surface plot of f(x, y, z) = c

My equation is of the form :

exp(- (625*(x - 31/20)^2)/72   -  (625*(x - 981/250)^2)/72 - (625*(y - 461/100)^2)/72 -  (625*(y - 4797/1000)^2)/72 - (625*(z - 13207/1000)^2)/72 - (625*(z - 15177/1000)^2)/72) = 0.0005 

It contains more terms in x, y, z, but they are of the same form (625*((X - var)^2)/72) where X is {x, y, z} and inside the exponent. Can I obtain 3d surface plot for this using this ? Edit :: Can I instead have a plot with negative signs with Matlab avoiding too large values.

Upvotes: 0

Views: 146

Answers (1)

Axel
Axel

Reputation: 1475

You can create surface plots of implicit functions in Matlab like this:

f = @(x,y,z) exp((625*(x - 31/20)^2)/72 + (625*(x - 981/250)^2)/72 + (625*(y - 461/100)^2)/72 + (625*(y - 4797/1000)^2)/72 + (625*(z - 13207/1000)^2)/72 + (625*(z - 15177/1000)^2)/72) - 0.0005;

fimplicit3(f)

However in your case if you analyze your equation in Wolfram Alpha you can see that an alternate form of it is

Alternate form of equation

Matlab won't be able to plot this as it will interpret all calculated values as Inf. You would need to do some scaling of your function first.

You can check what the largest finite floating-point number in IEEE double precision is by using realmax. This will give you 1.7977e+308.

EDIT

Matlab is able to plot some parts of the above function without the 8.12e1759 pre-factor. This will look like this:

Surface plot of alternate form of function

However as you can see Matlab is not able to display a surface at every position, as your function still behaves unexpectedly.

** EDIT 2 **

Ander Biguri suggested to look at the function in the proximity of the origin.

If we do so like this:

f = @(x,y,z) exp(5/288 .* (2 .* x .* (500 .* x - 2737) + y .* (1000 .* y - 9407) + 8 .* z .* (125 .* z - 3548))) - 0.0005;

interval = [-0.6 0.6 -0.6 0.6 -0.6 0.6];

%interval2 = [-6 6 -6 6 -6 6];

fimplicit3(f,interval)

colorbar

and then look at the result from the top, we get a nice contour plot that looks like this:

Contours plot in interval close to origin

Notice that hear I also vectorized your function for performance reasons.

I can't explain why for larger intervals even parts that look fine in this smaller interval cannot be displayed by Matlab. For example if I use interval2 instead the result looks like this:

Contour plot for wider range

Upvotes: 2

Related Questions