How to plot a circle given its equation (with colors)

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?

 Accepted Answer

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')
You can read more about setting line properties here.

1 Comment

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])

Sign in to comment.

More Answers (0)

Categories

Products

Tags

Community Treasure Hunt

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

Start Hunting!