Differential equation plotting semicircle instead of circle?

8 views (last 30 days)
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 Comment
Torsten
Torsten on 23 Jan 2019
Edited: Torsten on 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).

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!