Solve 2 quadratic equations
조회 수: 7 (최근 30일)
이전 댓글 표시
I have 2 quadratic equations with 2 known and 2 unknown. Ho do I write a script file to solve this equation. The equations are: (x1-xc)^2+(y1-yc)^2=R^2 (x2-xc)^2+(y2-yc)^2=R^2 I know the values for x1,x2,y1,y2 and R, these can be input manually in the script. I need to find xc and yc. How do I write a code to solve it in Matlab. Any help would be greatly appreciated.
댓글 수: 0
채택된 답변
Rajan Chauhan
2015년 11월 11일
syms xc;
syms yc;
[x y] = solve('(x1-xc)^2+(y1-yc)^2=R^2 ,(x2-xc)^2+(y2-yc)^2=R^2')
put the values of R ,x1 and y1 in above equation you will get your answer hopefully
댓글 수: 2
Rajan Chauhan
2015년 11월 12일
which version you are using ?? try this:
syms x y integer
[x y] = solve('(x1-xc)^2+(y1-yc)^2=R^2 ,(x2-xc)^2+(y2-yc)^2=R^2')
추가 답변 (1개)
Walter Roberson
2015년 11월 12일
Undefined function or method 'syms' for input arguments of type 'char'.
indicates that either you do not have the Symbolic Toolbox licensed or you do not have it installed. If you have the Student Version then it includes a license for the Symbolic Toolbox, and you should install it and try again with
make your assignments to x1, y1, x2, y2 and R above this point
syms xc yc
[XC, YC] = solve((x1-xc)^2+(y1-yc)^2 - R^2, (x2-xc)^2+(y2-yc)^2 - R^2, xc, yc);
If you do not have the symbolic toolbox available then there are method involving the optimization toolbox and fsolve() . And if you do not have that toolbox then you can do things like
initialvals = rand(1,2);
XCYC = fminsearch( @(xyc) (x1-xyc(1))^2+(y1-xyc(2))^2 - R^2 + (x2-xyc(1))^2+(y2-xyc(2))^2 - R^2, initialvals);
Be careful: there are two solutions.
In code, with the two solutions being xc1, yc1 and xc2, yc2:
t1 = -y1 + y2;
t2 = (x1 - x2);
t3 = (t2 ^ 2);
t4 = (x1 ^ 2);
t6 = 2 * x2 * x1;
t7 = x2 ^ 2;
t8 = (y1 ^ 2);
t9 = (y1 * y2);
t10 = 2 * t9;
t11 = (y2 ^ 2);
t14 = (R ^ 2);
t18 = sqrt((t3 * (t4 - t6 + t7 + t8 - t10 + t11) * (4 * t14 - t4 + t6 - t7 - t8 + t10 - t11)));
t22 = -t1;
t23 = (t22 ^ 2);
t24 = t4 - t6 + t7 + t23;
t25 = t2 * (x1 + x2) * t24;
t27 = 1 / t2;
t29 = 1 / t24;
t31 = t8 * y1;
t32 = t8 * y2;
t36 = (-x2 + x1 - y2) * (-x2 + x1 + y2) * y1;
t37 = t11 * y2;
t38 = t3 * y2;
t45 = 1 / (2 * t8 - 4 * t9 + 2 * t11 + 2 * t3);
xc1 = (t1 * t18 + t25) * t27 * t29 / 2;
yc1 = (t31 - t32 + t36 + t37 + t38 + t18) * t45;
xc2 = (t18 * t22 + t25) * t27 * t29 / 2;
yc2 = (t31 - t32 + t36 + t37 + t38 - t18) * t45;
댓글 수: 2
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!