Plotting an implicit function?
古いコメントを表示
I have the following equation:
F(x,y) = sqrt( (x^2 * y)^-0.2))
where x and y are positive.
The general shape should look like this:

and I was wondering how I would go about plotting that in matlab, after my unsuccessful attempts with ezplot.
1 件のコメント
回答 (1 件)
You could use ezplot, e.g.,
>> F=@(x,y) sqrt((x.^2.*y)-0.2)
>> ezplot(F,[0,2]); shg
8 件のコメント
J
2014 年 12 月 21 日
Worked fine for me. What do you mean "sets the eq equal to zero"? All implicit functions can be written as a homogeneous equation,
F(x,y)=0
J
2014 年 12 月 21 日
John D'Errico
2014 年 12 月 21 日
編集済み: John D'Errico
2014 年 12 月 21 日
I had a funny feeling that was to be the intent.
The warning message you received was not an error however. It merely told you that your function can be evaluated more quickly IF you did as suggested. Here, for example, it would help if you used .* instead of *, and .^ instead of ^ for the operators. Those dotted operators allow for elementwise multiplication and exponentiation, instead of linear algebra operations.
The problem arises because the plot you show is not the solution to that equation. Without a right hand side (a constant term) the right hand side must be assumed to be implicitly zero. Therefore the only "solution" is comprised of the locus x=0 OR y=0.
So if you insist on plotting the curve with some non-zero right hand side, then you must build it into the implicit function. MATLAB cannot guess that there is actually some non-zero constant there if you do not provide it.
For example, if I pick 1 as a nominal right hand side, and use the more friendly set of operators...
ezplot('sqrt((x.^2 * y).^(-0.2)) - 1')
grid on

Note that I also enclosed the exponent there with parens to make the exponentiation clear and the code easier to read.
If you truly want only the first quadrant shown, this too can be achieved, most easily by simply setting the axis limits as you wish.
J
2014 年 12 月 21 日
Thanks, but my difficulty is knowing quite what to set it equal to to achieve the desired result.
That's not a plotting problem, but rather a curve fitting problem. If you already know what points (x,y) should lie on the plot, then you should be able to calculate RHS directly
RHS=F(xi,yi)
where xi and yi are a pair of sample points. If RHS has a specific parametric form, you could possibly use lsqnonlin to estimate them, if you have the Optimization Toolbox.
and I wanted to know how and if the same could be achieved in matlab
No, it cannot. Clearly the equation explorer site is using some hidden choice of RHS constant which is not equal to zero. One can see mathematically that the plot is wrong if RHS=0 were used. It makes no sense really. And of course, you wouldn't want MATLAB or any other software tool to make similar random choices.
John D'Errico
2014 年 12 月 21 日
編集済み: John D'Errico
2014 年 12 月 21 日
Therein lies the problem with the internet. Some random person can post a web site that makes any claim they want. You need to think about what you see and decide if it makes sense, or it is simply a pusher of mental pablum. This is true in general, and of course true in mathematics.
An implicit function only makes sense IF there is an equality in there. Otherwise, you have nothing. So what is F(x,y) equal to? Perhaps 1? 0? pi? 17? Ah! Yes it must be 42.
My point is, you will generally see different curves, depending on the value of that unspecified right hand side. Lacking anything else provided by you, MATLAB makes the perfectly reasonable assumption that it must be zero, and that any necessary constant was built into the function F as provided by you. Any other assumption would simply be wrong.
Since you seem confused, I'll offer a web site ( wikipedia ) that explains what is an implicit function. Of course, then you need to read and decide if what you see is true. I might make note of the form it shows, with an equality and a right hand side of zero. I'm not saying that Wikipedia is perfect of course, hey it could be a lie.
J
2014 年 12 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!