Differential equation plotting semicircle instead of circle?

Problem: (dy/dx) = (-x/y) , condition: y(sqrt(2)) = sqrt(2)
After solving equation on paper I got equation of a circle x^2 + y^2 = 4, but matlab plots a semicircle of radius 2. Why is this happening?
Code:
eqn='Dy=-x/y';
ini='y(sqrt(2))=sqrt(2)';
y=dsolve(eqn,ini,'x');
disp(y);
x=-2:0.1:2;
y1=eval(vectorize(y));
plot(x,y1)

1 commentaire

Torsten
Torsten le 23 Jan 2019
Modifié(e) : Torsten le 23 Jan 2019
Two functions are solutions to your ODE:
y1(x)=sqrt(4-x^2) and y2(x)=-sqrt(4-x^2)
Since "dsolve" returns a function, not a relation as solution to your ODE, it will either return
y1(x) or y2(x).

Connectez-vous pour commenter.

Réponses (0)

Modifié(e) :

le 23 Jan 2019

Community Treasure Hunt

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

Start Hunting!

Translated by