Solving two equations with two unknows
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi All,
I am trying to solve two equations I have with two unknowns using MATLAB, its not working with me. This is my code:
syms xC yC
a = 11.3;
b = 11.3;
A = [0 0];
B = [0 10];
xA = A(1)
yA = A(2)
xB = B(1)
yB = B(2)
b^2 = (xC -xA)^2 + (yC - yA)^2 % equation one
a^2 = (xC -xB)^2 + (yC - yB)^2 % equation two
how can I solve these two equations and find xC and yC?
Thanks in advance
댓글 수: 0
채택된 답변
Roger Stafford
2013년 11월 13일
You could undoubtedly solve these two equations using 'solve' of the Symbolic Toolbox or 'fsolve' of the Optimization Toolbox. However, this is the classic problem of finding the two intersections of two circles which is well understood, and the following matlab code is very likely more efficient than either of these methods.
Let P1 and P2 be column vectors containing the coordinates of the two circles' centers - [xA;yA] and [xB;yB] in your case - and let r1 and r2 be the two respective radii. Then the two intersections of the circles are points Q1 and Q2 where Q1 lies off to the left and Q2 off to the right as you move from P1 toward P2.
P21 = P2-P1;
d2 = sum((P21).^2);
P0 = (P1+P2)/2+(r1+r2)*(r1-r2)/2/d2*P21;
Q0 = sqrt(((r1+r2)^2-d2)*(d2-(r1-r2)^2))/2/d2*[0,-1;1,0]*P21;
Q1 = P0+Q0;
Q2 = P0-Q0;
Note: For the above Q0 computation to work properly it is essential that P1 and P2 be column vectors, not row vectors. If they are row vectors, the Q0 code should be changed to its transpose:
Q0 = sqrt(((r1+r2)^2-d2)*(d2-(r1-r2)^2))/2/d2*P21*[0,1;-1,0];
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!