How to solve for x give the equation of a circle and the equation of a line?
38 views (last 30 days)
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.
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]);
% plot curves
fimplicit(eq1,[-5 10 -10 5]); hold on
fimplicit(eq2,[-5 10 -10 5])
% plot solution points
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.