Why I couldn't plot this graph f=(@(x,y) (x.^2)+(x*y)+(y.^2)<=68200.^2/3);
2 views (last 30 days)
Alan Stevens on 4 Mar 2023
This will give you the outline (I've assumed you want 68200^(2/3) rather than 68200^2/3)
John D'Errico on 4 Mar 2023
Edited: John D'Errico on 4 Mar 2023
The issue is, tools like fimplicit do not plot inequalities. That is, if there were an equality in there, then this would be a problem a tool that fimplicit could solve, just drawing the curve of the implicit equation. But you have also got an inequality. So you apparently want to show all points that are inside the indicated ellipse.
That is possible in this case. For example, we could create a list of points on the ellipse, and then use them to describe a polygon. Now a tool like polyshape wold suffice to very easily draw the curve, as well as fill it in. For example, assuming you really did intend what was written there as 68200.^2/3, and not 68200.^(2/3) as some have guessed, I might do this.
First, generate points on the curve itself.
syms theta r real
x = r*cos(theta);
y = r*sin(theta);
eq = simplify((x.^2)+(x*y)+(y.^2) == 68200.^2/3)
rsol = solve(eq,r)
As you can see, we want the positive root.
rfun = matlabFunction(rsol(2))
Now the ellipse is simply generated.
t = linspace(0,2*pi,1000);t(end) = ;
xe = rfun(t).*cos(t);
ye = rfun(t).*sin(t);
You can see the ellipse is as you would have expected.
PS = polyshape(xe,ye);
But the polyshape plot is probably what you wanted.
Was that simple? Not totally, but as I said, MATLAB does not have a general facility to plot the region of an implicit inequality. In many cases, that region might not be finite. For exmple, it would be trivial to change your problem so that it now described a hyperbola. I would need to change only the sign of one of those terms. Would such a tool be a useful thing to have in MATLAB? Perhaps, so this is arguably worth a feature request.
Is there a simpler way to achive the solution of thois problem, that does not invold the creation of a polyshape? Well, yes. For example, we might do this:
[X,Y] = meshgrid([-60000:100:60000]);
Z = +((X.^2)+(X.*Y)+(Y.^2) <= 68200.^2/3);
H = pcolor(X,Y,Z);H.EdgeColor = 'none';
colormap([1 1 1;0 0 .75])