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

19 次查看(过去 30 天)
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
Matt J 2021-12-3
编辑:Matt J 2021-12-3
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

更多回答(2 个)

DGM
DGM 2021-12-3
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
Jon 2021-12-3
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 个评论
Jon
Jon 2021-12-3
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Equation Solving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by