How to plot a circle given its equation (with colors)
18 views (last 30 days)
Show older comments
Wilson Zheng
on 20 Mar 2020
Commented: Cris LaPierre
on 20 Mar 2020
I have 2 equations:
x^2+y^2=1/2
(x-1)^2+y^2=1
How can I quickly and easily plot both equations in the same graph, but with different colors. ezplot works and is super simple, but I can't find a way to change the colors. plot and fplot seems to be struggling with the "=" sign. What's the quickest way to do this?
0 Comments
Accepted Answer
Cris LaPierre
on 20 Mar 2020
Edited: Cris LaPierre
on 20 Mar 2020
You could rearrange the equations to be in the form "y=..." and then use fplot on that.
y=@(x) sqrt(1/2 - x.^2);
fplot(y,'--or')
1 Comment
Cris LaPierre
on 20 Mar 2020
Of course, the challenge is to get a circle, you need the positive and negative results. You could do this symbolically
syms x y
eqn = x.^2 + y.^2 == 1/2
s = solve(eqn,x)
fplot(s,[-1,1])
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!