MATLAB Answers

Solving non linear equation "Circle" equations

조회 수: 6(최근 30일)
Ahmed Ashour
Ahmed Ashour 2021년 9월 15일
댓글: Ahmed Ashour 2021년 9월 16일
Hello I have a 20 non linear equations that I want to solve, I started with only three to check if it would be working but I always get an empty vector. I do not get any answers.
syms xa ya
eq1 = xa^2 + ya^2 == 84.4^2;
eq2 = (xa-40)^2 + ya^2 == 68^2;
eq3 = (xa-100.66)^2 + (ya-49.07)^2 == 52.59^2;
sol = solve([eq1, eq2, eq3],[xa,ya])
for example the above 3 circles intersect at one point which should be (51.24, 67.06) but I always get an empty object. I know I can solve each 2 of them seperately and compare results, but my main object is to solve 20 equations with 15 unknowns at once.
but even for 2 unknowns I do not get answers.
sol =
struct with fields:
xa: [0×1 sym]
ya: [0×1 sym]
  댓글 수: 5
Matt J
Matt J 2021년 9월 15일
So, write the complete number and we will check that too.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2021년 9월 15일
편집: Matt J 2021년 9월 15일
Because you cannot be certain of an exact 3-way (or n-way) intersection, you need to use a numerical least squares solver like fsolve.
opts=optimoptions(@fsolve,'StepTol',1e-8,'FunctionTol',1e-8,'OptimalityTol',1e-8);
[xy,Fxy]=fsolve(@modelEq,[51.24, 67.06],opts)
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
Equation solved, solver stalled. fsolve stopped because the relative size of the current step is less than the value of the step size tolerance and the vector of function values is near zero as measured by the value of the function tolerance.
xy = 1×2
51.2421 67.0642
Fxy = 1×3
0.0036 -0.0043 0.0027
function F=modelEq(p)
xa=p(1); ya=p(2);
eq1 = xa^2 + ya^2 - 84.4^2;
eq2 = (xa-40)^2 + ya^2 - 68^2;
eq3 = (xa-100.66)^2 + (ya-49.07)^2 - 52.592^2;
F=[eq1, eq2, eq3];
end
  댓글 수: 1
Ahmed Ashour
Ahmed Ashour 2021년 9월 16일
Thanks for your elaboration. it is all clear now.
it was my mistake from the beginning as I wanted to avoid numerical solutions because I do not want to bias the system with my initial guesses.

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Walter Roberson
Walter Roberson 2021년 9월 15일
syms xa ya R3
xc = [0; 40; 100.66];
yc = [0; 0; 49.07];
r3 = 52.59;
R = [84.4; 68; R3];
eqn = (xa-xc).^2 + (ya-yc).^2 == R.^2;
sol = solve(eqn(1:2), [xa, ya])
sol = struct with fields:
xa: [2×1 sym] ya: [2×1 sym]
sol.xa
ans = 
sol.ya
ans = 
r3_needed = sqrt(lhs(vpa(subs(eqn(3), sol))))
r3_needed = 
r3_needed - r3
ans = 
RR = double([R(1:2); r3_needed(2)]);
viscircles([xc, yc], RR, 'Color', 'k')
ans =
Group with properties: Children: [2×1 Line] Visible: on HitTest: on Show all properties
hold on
scatter(sol.xa, sol.ya, 60, 'r+')
hold off

Bjorn Gustavsson
Bjorn Gustavsson 2021년 9월 15일
If the 20 equations are of the same form you will have a vastly overdetermined problem (that in general will not have any exact solution which will lead you to some kind of least-squares like solutions). The most natural first-stab might be to simply solve pairwise problems and then check if you have any common solution to all (or some subsets).
  댓글 수: 3
Ahmed Ashour
Ahmed Ashour 2021년 9월 16일
I get it now, sorry for the confusion I made.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by