Need help in finding all the solutions of non linear ellipse equations using Newtons Method using following code.

15 views (last 30 days)
I am trying to find all the solutions of non linear ellipse equations using Newtons Method using the following code but it only gives me 2 sets of answers no matter the initial guess value.
How can I find all the coordinates of intersection using the following code
func = @(x) [(x(1)+x(2)+2)^2+(x(1)+3)^2-5; 2*(x(1)+3)^2+(x(2)/3)^2-4];
% Jacobian of the Above system calculated
jacobi_func = @(x) [4*x(1)+2*x(2)+10,2*x(1)+2*x(1)+4;4*x(1)+12,2*x(2)/9];
%Define the stopping criteria i-e the tolerance value
tol = 10^-4;
% Define the initial guess
% Note that this effects our final value
% First Coordinate
x = [-1.62;1.38] ;
no_itr = 10 ;
x1 = x;
fnx1 = feval(func,x1);
i = 0;
fprintf(' Iteration| x | y | Error | \n')
while true
norm1 = norm(fnx1);
fprintf('%10d |%10.4f| %10.4f | %10.4d |\n',i,x1(1),x1(2),norm1)
jacob_fnx1 = feval(jacobi_func,x1);
H = jacob_fnx1\fnx1;
x1 = x1 - H;
fnx1 = feval(func,x1);
i = i + 1 ;
norm1 = norm(fnx1);
if i > no_itr && norm1 < tol, break , end
%if norm(fnv1) < error , break , end
It only gives me two sets of coordinates but these elllipses have four intersection points
The equations of ellipses are
(x+y+2)^2 + (x+3)^2 = 5
2*(x+3)^2 + (y/3)^2 = 4

Accepted Answer

Walter Roberson
Walter Roberson on 22 Feb 2022
Look at the dimensionality of the problem. At any one time you have one pair of values in "x" (but which you treat as an x-y pair). You loop through using information from a function that has 2 outputs and 2 x 2 jacobian, so using Newton's Method, you get out 2 results -- an updated x/y pair. At the end of the loop you have at most one x/y pair; you cannot possibly get four x/y pairs out of this code.
Or are you trying to say that no matter what initial coordinates you use, that the result always settles on one of two locations, and your code does not seem to be able to reach the other locations?
If so.. what happens if you use the other locations as the initial values? Does it not decide the point is within tolerance? How about if you put in something very "close" to the other locations: does it move the small distance, or does it always diverge away to one of the two locations?
If passing in the known other locations does not decide that the point is a match, then you have an error in your calculations or an error in the convergence test.
Haseeb Hashim
Haseeb Hashim on 26 Feb 2022
Thanks again for detailed explanation but as I said before the Jacobian at 1st row and second column is
in place of
thats why my other answers were not converging but anyways I learned lot of other things form your answer.

Sign in to comment.

More Answers (2)

Alan Stevens
Alan Stevens on 22 Feb 2022
Check your Jacobian equations, especially the term:
I think this should be

Torsten on 22 Feb 2022
Maybe a symbolic approach is want you want:
syms x y
res1 = (x+y+2)^2 + (x+3)^2 - 5 == 0;
res2 = 2*(x+3)^2 + (y/3)^2 - 4 == 0;
s = solve([res1,res2],[x,y])

Community Treasure Hunt

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

Start Hunting!

Translated by