Why I couldn't plot this graph f=(@(x,y) (x.^2)+(x*y)+(y.^2)<=68200.^2/3);
1 回表示 (過去 30 日間)
古いコメントを表示
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/
0 件のコメント
回答 (3 件)
Alan Stevens
2023 年 3 月 4 日
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
0 件のコメント
Askic V
2023 年 3 月 4 日
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])
0 件のコメント
John D'Errico
2023 年 3 月 4 日
編集済み: John D'Errico
2023 年 3 月 4 日
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.
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 件のコメント
John D'Errico
2023 年 3 月 4 日
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
2023 年 3 月 4 日
I really wonder if it is
((68200.^2)/3)
or if it is intended to be
(68200.^(2/3))
参考
カテゴリ
Help Center および File Exchange で Discrete Data Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!