Effacer les filtres
Effacer les filtres

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

9 vues (au cours des 30 derniers jours)
econogist
econogist le 16 Mar 2020
Commenté : econogist le 19 Mar 2020
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')

Réponses (2)

tmarske
tmarske le 16 Mar 2020
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 commentaires
econogist
econogist le 17 Mar 2020
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 le 17 Mar 2020
Modifié(e) : Walter Roberson le 17 Mar 2020
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)

Connectez-vous pour commenter.


econogist
econogist le 17 Mar 2020
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)
  2 commentaires
Walter Roberson
Walter Roberson le 17 Mar 2020
plot(subs(S), y)
econogist
econogist le 19 Mar 2020
Thank you! This worked great!

Connectez-vous pour commenter.

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by