# How to solve for x give the equation of a circle and the equation of a line?

38 views (last 30 days)
Xav Sholin on 3 Dec 2021
Answered: DGM on 3 Dec 2021
I am given the equation of a circle and equation of a line how can I solve for x using matlab code. I understand how to do this on paper but I am not sure how to do it on matlab. Any help would be greatful. <3 Where -2 is the x-coordinate of the center of the circle, 3 is the y coordinate of the center of the circle and 4 is the radius squared of the circle. Matt J on 3 Dec 2021
Edited: Matt J on 3 Dec 2021
If you have the Symbolic Math Toolbox
syms x y
sol=solve((x-2)^2+(y+3)^2==4, 2*x+2*y==-1);
double( sol.x )
ans = 2×1
3.6419 0.8581
double( sol.y )
ans = 2×1
-4.1419 -1.3581

### More Answers (2)

DGM on 3 Dec 2021
Consider the example of finding the intersection of a parabola and a circle. Note that this can all be done with the equations in implicit form.
syms x y real
eq1 = (x-3)^2 + (y+3)^2 == 4^2;
eq2 = 2*x + (y+1)^2 == 5;
S = solve([eq1 eq2],[x y]);
S.x
ans = S.y
ans = double(S.x)
ans = 2×1
-0.9506 1.2359
double(S.y)
ans = 2×1
-3.6270 0.5900
% plot curves
fimplicit(eq1,[-5 10 -10 5]); hold on
fimplicit(eq2,[-5 10 -10 5])
% plot solution points
plot(double(S.x),double(S.y),'ko') Jon on 3 Dec 2021
You can use MATLAB's fsolve to solve the original system of two equations and two unknowns. To do this you have to rearrange the equation so that the right hand side is equal to zero, and then solve for the value of x and y that satisfy this using fsolve.
Alternatively, once you have substituted for y, as you show in your lower equation you can expand that as a second order polynomial , once again rearranging to make the right hand side equal to zero and solve for the roots (values of x that make the function equal to zero) using MATLAB's roots function.
##### 1 CommentShowHide None
Jon on 3 Dec 2021
To find out more about either of these functions, type doc followed by the function name on the command line, so
doc fsolve
doc roots
Also, if you have the symbolic math toolbox, there are further options. I don't have this so I can't offer any other specifics