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

조회 수: 23 (최근 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