Why is there a jagged line when I plot this function?

Hi guys,
I am trying to plot an implicit function and am getting strange results. I understand the smooth part of the function, but not the jagged part. Why is the jagged part there at all? Also, what can I do to eliminate it?
Here's the code:
f1=(@(x,y) (5.*y.^(1./2) -3)./(2.5.*y.^(1./2)+2.5.*x.^(1./2)-3)-y);
fimplicit(f1,[0 4 0 4],'black')

답변 (2개)

tmarske
tmarske 2020년 3월 16일
It's because fimplicit is using too few evaluation points, resulting in too coarse an interpolation (by default it uses 151). You can override this using the 'MeshDensity' argument:
f1=(@(x,y) (5.*y.^(1./2) -3)./(2.5.*y.^(1./2)+2.5.*x.^(1./2)-3)-y);
fimplicit(f1,[0 4 0 4],'black', 'MeshDensity', 5000)

댓글 수: 6

Thanks for your response tmarske. So how can I eliminate that part of the plot completely? I don't want it to be smooth or jagged, I want to try to get rid of it entirely.
What would you expect the result to look like? There are two lower-branch solutions for each x, and at some point they become equal and cross; what would you discard?
I expected it to look like it does in the attachment done here in Desmos. Why does it look different here compared to Matlab?
Ah, what is happening is that your function has a discontinuity in it, and what fimplicit is detecting is not a zero but rather a sign change.
Thanks for that! I see what you mean. So is there anyway I can get rid of that part of the plot completely? I tried limiting the range, but that gets rid of the part I want as well.
Walter Roberson
Walter Roberson 2020년 3월 17일
편집: Walter Roberson 2020년 3월 17일
If you have the symbolic toolbox, you can solve f1 for x in term of y to get a single x for each y. you can then linspace() for y and put those through the equation to derive x, and then plot(x,y)

댓글을 달려면 로그인하십시오.

econogist
econogist 2020년 3월 17일
I do have the symbolic toolbox. I'm trying to do what you said but still having some trouble as I'm new to matlab. I think I'm on the right track, but it's coming up with an error message.
Here is what I have so far:
syms x y
eqn=(5.*y.^(1/2) -3)./(2.5.*x.^(1./2)+2.5.*y.^(1/2)-3)==y;
S=solve(eqn, x);
y=linspace(0,100);
plot(S,y)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2020년 3월 16일

댓글:

2020년 3월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by