# Why I couldn't plot this graph f=(@(x,y) (x.^2)+(x*​y)+(y.^2)<​=68200.^2/​3);

3 views (last 30 days)
Tachaphong on 4 Mar 2023
Commented: Walter Roberson on 4 Mar 2023
f=(@(x,y) (x.^2)+(x*y)+(y.^2)<=68200.^2/3);
fimplicit(f)
grid on
Could you please review my code and provide me an advice what should I do to generate this graph. I tried several times but there is no graoh occured/

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)
f=@(x,y) x.^2+x.*y+y.^2-68200.^(2/3);
fimplicit(f,[-80 80])
grid on Askic V on 4 Mar 2023
And if you really insist on 68200^2/3, then this code will provide output
f=@(x,y) x.^2+x.*y+y.^2-68200^2/3;
fimplicit(f, 'b')
grid on
xlim([-50000 50000]);ylim([-50000 50000]) 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)
eq = rsol = solve(eq,r)
rsol = As you can see, we want the positive root.
rfun = matlabFunction(rsol(2))
rfun = function_handle with value:
@(theta)sqrt(2.0).*6.203122350668009e+6.*1.0./sqrt(sin(theta.*2.0)+2.0).*6.34765625e-3
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.
plot(xe,ye) PS = polyshape(xe,ye);
plot(PS) 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]) Walter Roberson on 4 Mar 2023
I really wonder if it is
((68200.^2)/3)
or if it is intended to be
(68200.^(2/3))