4D plot?
2 views (last 30 days)
Show older comments
Hi All,
I have been struggeling with how to plot the following, and I'm hoping anyone has any ideas on this.
I have this extreme value problem: F(x,y,z)=x^2+y^2+z^2 subject to g(x,y,z)=x^4+y^4+z^4=1. I would like to get a visual of f(x,y,z), and then project g(x,y,z)=1 on f(x,y,z).
I used the following code
[x,y,z] = meshgrid( linspace( -1, 1, 200 ) );
f = x.^2 +y.^2 +z.^2;
figure(1)
isosurface(x, y, z, f)
hold on
[x,y,z] = meshgrid( linspace( -1, 1, 200 ) );
f = x.^4 +y.^4 +z.^4;
figure(1)
isosurface(x, y, z, f,1)
But I have the feeling that this is not correct, as f(x,y,z) should be a sphere (I thought so at least)...
Any thoughts on how to fix this issue?
0 Comments
Answers (1)
Walter Roberson
on 21 Aug 2020
Edited: Walter Roberson
on 21 Aug 2020
g tells you that x^4+y^4+z^4 = 1
Therefore z^2 = +/- sqrt(1 - x.^4 - y.^4)
Substitute into x^2 + y^2 + z^2 to get
fg = x.^2 + y.^2 +/- sqrt(1 - x.^4 - y.^4)
This does not need a 3d mesh, only a 2d mesh. You will, however, have to break it into two pieces for the +/-
You cannot plot f directly as it is unbounded. You can plot isosurfaces of it, one at a time; each of which is a sphere.
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!