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

1 view (last 30 days)
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/

Answers (3)

Alan Stevens
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
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
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])
  5 Comments
John D'Errico
John D'Errico on 4 Mar 2023
I'd not call it a dumb question. In fact, in the feature request I posted to TMW, I suggested that fimplicit could be adapted to allow an inequality. SHOULD it do that, as the code exists now? No. Because it was not written to handle that class of problem. Yes, in an ideal world, in a future release, maybe it should. Perhaps they could offer an option in fimplicit to specify the implicit equality should be interpreted as an inequality.
Would it be a useful feature? Yes, I think so. I've had at least two answers I've written that could have benefited from such a tool only in the last few months.
Walter Roberson
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))

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!