# Initial Conditions for Newton Raphson Method for 9 equations 9 unknowns problem set

6 visualizaciones (últimos 30 días)
Haleema Qamar el 22 de Mzo. de 2024
Comentada: Alex Sha el 27 de Mzo. de 2024
Hi, I am trying to solve these 9 equations for alpha1, alpha2, alpha3, ...... alpha9
-1+2*(cos(alpha1)-cos(alpha2)+cos(alpha3)-cos(alpha4)+cos(alpha5)-cos(alpha6)+cos(alpha7)-cos(alpha8)+cos(alpha9));
-1+2*(cos(5*alpha1)-cos(5*alpha2)+cos(5*alpha3)-cos(5*alpha4)+cos(5*alpha5)-cos(5*alpha6)+cos(5*alpha7)-cos(5*alpha8)+cos(5*alpha9));
-1+2*(cos(7*alpha1)-cos(7*alpha2)+cos(7*alpha3)-cos(7*alpha4)+cos(7*alpha5)-cos(7*alpha6)+cos(7*alpha7)-cos(7*alpha8)+cos(7*alpha9));
-1+2*(cos(11*alpha1)-cos(11*alpha2)+cos(11*alpha3)-cos(11*alpha4)+cos(11*alpha5)-cos(11*alpha6)+cos(11*alpha7)-cos(11*alpha8)+cos(11*alpha9));
-1+2*(cos(13*alpha1)-cos(13*alpha2)+cos(13*alpha3)-cos(13*alpha4)+cos(13*alpha5)-cos(13*alpha6)+cos(13*alpha7)-cos(13*alpha8)+cos(13*alpha9));
-1+2*(cos(17*alpha1)-cos(17*alpha2)+cos(17*alpha3)-cos(17*alpha4)+cos(17*alpha5)-cos(17*alpha6)+cos(17*alpha7)-cos(17*alpha8)+cos(17*alpha9));
-1+2*(cos(19*alpha1)-cos(19*alpha2)+cos(19*alpha3)-cos(19*alpha4)+cos(19*alpha5)-cos(19*alpha6)+cos(19*alpha7)-cos(19*alpha8)+cos(19*alpha9))
-1+2*(cos(23*alpha1)-cos(23*alpha2)+cos(23*alpha3)-cos(23*alpha4)+cos(23*alpha5)-cos(23*alpha6)+cos(23*alpha7)-cos(23*alpha8)+cos(23*alpha9))
-1+2*(cos(29*alpha1)-cos(29*alpha2)+cos(29*alpha3)-cos(29*alpha4)+cos(29*alpha5)-cos(29*alpha6)+cos(29*alpha7)-cos(29*alpha8)+cos(29*alpha9));
I have used Newton Raphson Method for that, but my results don't converge. I believe the error is with the initial values of alpha1, alpha2, alpha3, ...... alpha9 that I am using. I am using random initial values as of now. All I know is that these angles alpha1 to alpha9 should be in the range of 0 to 90 degrees. I have read about using the correct initial value problem in Newton Raphson method and some articles say that "you should use a rough estimate of the root of the function, if you know it". But the problem is that I do not know the estimate root of the function.
I am attaching a 7-equations in 7 uknowns code that works (I did not find its initial values, they were given to me) and 9-equations in 9 unknowns code that does not work.
I appreciate any help in this regard. Thanks once again.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (2)

Torsten el 23 de Mzo. de 2024
Editada: Torsten el 23 de Mzo. de 2024
It's the same behaviour with "fsolve", MATLAB's nonlinear solver.
The seven equation problem is solved without problems, and the solver fails more or less for the nine equation problem.
Maybe it has no solution - who knows.
m1 = 0:0.01:1.15;
alpha1 = 2*pi/180;
alpha2 = 16*pi/180;
alpha3 = 28*pi/180;
alpha4 = 31*pi/180;
alpha5 = 43*pi/180;
alpha6 = 61*pi/180;
alpha7 = 73*pi/180;
alpha0 = [alpha1;alpha2;alpha3;alpha4;alpha5;alpha6;alpha7];
sol_alpha = zeros(numel(m1),7);
error = zeros(numel(m1),1);
for i = 1:numel(m1)
T = [m1(i)*pi/4; 0; 0; 0; 0; 0; 0];
F = @(alpha1,alpha2,alpha3,alpha4,alpha5,alpha6,alpha7)...
[-1+2*(cos(alpha1)-cos(alpha2)+cos(alpha3)-cos(alpha4)+cos(alpha5)-cos(alpha6)+cos(alpha7));
-1+2*(cos(5*alpha1)-cos(5*alpha2)+cos(5*alpha3)-cos(5*alpha4)+cos(5*alpha5)-cos(5*alpha6)+cos(5*alpha7));
-1+2*(cos(7*alpha1)-cos(7*alpha2)+cos(7*alpha3)-cos(7*alpha4)+cos(7*alpha5)-cos(7*alpha6)+cos(7*alpha7));
-1+2*(cos(11*alpha1)-cos(11*alpha2)+cos(11*alpha3)-cos(11*alpha4)+cos(11*alpha5)-cos(11*alpha6)+cos(11*alpha7));
-1+2*(cos(13*alpha1)-cos(13*alpha2)+cos(13*alpha3)-cos(13*alpha4)+cos(13*alpha5)-cos(13*alpha6)+cos(13*alpha7));
-1+2*(cos(17*alpha1)-cos(17*alpha2)+cos(17*alpha3)-cos(17*alpha4)+cos(17*alpha5)-cos(17*alpha6)+cos(17*alpha7));
-1+2*(cos(19*alpha1)-cos(19*alpha2)+cos(19*alpha3)-cos(19*alpha4)+cos(19*alpha5)-cos(19*alpha6)+cos(19*alpha7))];
F = @(alpha1,alpha2,alpha3,alpha4,alpha5,alpha6,alpha7)...
F(alpha1,alpha2,alpha3,alpha4,alpha5,alpha6,alpha7) - T;
F = @(alpha) F(alpha(1),alpha(2),alpha(3),alpha(4),alpha(5),alpha(6),alpha(7));
sol_alpha(i,:) = lsqnonlin(F,alpha0,zeros(7,1),pi/2*ones(7,1),[],[],[],[],[],optimset('Display','none','TolFun',1e-16,'TolX',1e-16));
alpha0 = sol_alpha(i,:);
error(i) = norm(F(sol_alpha(i,:)));
end
figure(1)
plot(m1,180/pi*sol_alpha)
alpha1=2*pi/180;
alpha2=16*pi/180;
alpha3=28*pi/180;
alpha4=31*pi/180;
alpha5=43*pi/180;
alpha6=61*pi/180;
alpha7=73*pi/180;
alpha8=81*pi/180;
alpha9=88*pi/180;
alpha0 = [alpha1;alpha2;alpha3;alpha4;alpha5;alpha6;alpha7;alpha8;alpha9];
sol_alpha = zeros(numel(m1),9);
error = zeros(numel(m1),1);
for i = 1:numel(m1)
T = [m1(i)*pi/4; 0; 0; 0; 0; 0; 0; 0; 0];
F = @(alpha1,alpha2,alpha3,alpha4,alpha5,alpha6,alpha7,alpha8,alpha9)...
[-1+2*(cos(alpha1)-cos(alpha2)+cos(alpha3)-cos(alpha4)+cos(alpha5)-cos(alpha6)+cos(alpha7)-cos(alpha8)+cos(alpha9));
-1+2*(cos(5*alpha1)-cos(5*alpha2)+cos(5*alpha3)-cos(5*alpha4)+cos(5*alpha5)-cos(5*alpha6)+cos(5*alpha7)-cos(5*alpha8)+cos(5*alpha9));
-1+2*(cos(7*alpha1)-cos(7*alpha2)+cos(7*alpha3)-cos(7*alpha4)+cos(7*alpha5)-cos(7*alpha6)+cos(7*alpha7)-cos(7*alpha8)+cos(7*alpha9));
-1+2*(cos(11*alpha1)-cos(11*alpha2)+cos(11*alpha3)-cos(11*alpha4)+cos(11*alpha5)-cos(11*alpha6)+cos(11*alpha7)-cos(11*alpha8)+cos(11*alpha9));
-1+2*(cos(13*alpha1)-cos(13*alpha2)+cos(13*alpha3)-cos(13*alpha4)+cos(13*alpha5)-cos(13*alpha6)+cos(13*alpha7)-cos(13*alpha8)+cos(13*alpha9));
-1+2*(cos(17*alpha1)-cos(17*alpha2)+cos(17*alpha3)-cos(17*alpha4)+cos(17*alpha5)-cos(17*alpha6)+cos(17*alpha7)-cos(17*alpha8)+cos(17*alpha9));
-1+2*(cos(19*alpha1)-cos(19*alpha2)+cos(19*alpha3)-cos(19*alpha4)+cos(19*alpha5)-cos(19*alpha6)+cos(19*alpha7)-cos(19*alpha8)+cos(19*alpha9))
-1+2*(cos(23*alpha1)-cos(23*alpha2)+cos(23*alpha3)-cos(23*alpha4)+cos(23*alpha5)-cos(23*alpha6)+cos(23*alpha7)-cos(23*alpha8)+cos(23*alpha9))
-1+2*(cos(29*alpha1)-cos(29*alpha2)+cos(29*alpha3)-cos(29*alpha4)+cos(29*alpha5)-cos(29*alpha6)+cos(29*alpha7)-cos(29*alpha8)+cos(29*alpha9))];
F = @(alpha1,alpha2,alpha3,alpha4,alpha5,alpha6,alpha7,alpha8,alpha9)...
F(alpha1,alpha2,alpha3,alpha4,alpha5,alpha6,alpha7,alpha8,alpha9) - T;
F = @(alpha) F(alpha(1),alpha(2),alpha(3),alpha(4),alpha(5),alpha(6),alpha(7),alpha(8),alpha(9));
sol_alpha(i,:) = lsqnonlin(F,alpha0,zeros(9,1),pi/2*ones(9,1),[],[],[],[],[],optimset('Display','none','TolFun',1e-16,'TolX',1e-16));
alpha0 = sol_alpha(i,:);
error(i) = norm(F(sol_alpha(i,:)));
end
figure(2)
plot(m1,180/pi*sol_alpha)
##### 2 comentariosMostrar NingunoOcultar Ninguno
Haleema Qamar el 25 de Mzo. de 2024
Thanks @Torsten for your response. I am bit lost here. The code snippet that you just added shows that the solution does exist for 9-equation system too. But my query was about the initial values. I know that the solution exists for 9-equation system too, but I am stuck at using the correct initial values that will actually give me a solution using Newton Raphson method.
Also, this code snippet does not work for me. Attached is the error I am getting. Thanks.
Torsten el 25 de Mzo. de 2024
Editada: Torsten el 25 de Mzo. de 2024
If you plot the "error" array of the 9-equations system, you will see that the values "fsolve" returns are not solutions for your equations. So I can neither give you good initial values nor a solution.
@Alex Sha gave you three solutions for your 9-equations system with m1 = 0. He uses a different software (not MATLAB), and my guess is that he obtained them by trial-and-error.

Iniciar sesión para comentar.

John D'Errico el 23 de Mzo. de 2024
1. Not every system of equations you will write down has a solution.
2. Starting from a random position does not insure you will find a solution. In fact, for complex problems, it may often fail.
Think of an optimizer as putting a blind person down at some place on earth, and asking them to find the location on the surface of the earth with the lowest elevation. All they are given is a cane, to determine a direction to walk that is downhill, and an altimeter (with audio output I hope.)
Would you expect that setting this person down in some random location would let them find the lowest spot on earth? Or, would they likely find themselves stuck in a bad place? That is, unable to move in any direction, because locally, they need to walk uphill?
That is effectively what you are doing when you provide random starting values to the solver.
Is there any magic way to automatically choose good starting values? Of course not. In fact, that is impossible to do for a completely general nonlinear system of equations. This is why there are tools in the Global Optimization toolbox, to try to solve difficult problems where no intelligent starting values are available.
##### 10 comentariosMostrar 8 comentarios más antiguosOcultar 8 comentarios más antiguos
Torsten el 26 de Mzo. de 2024
Editada: Torsten el 26 de Mzo. de 2024
Another condition was 0 <= alpha <= pi/2.
Seems there is no solution satisfying this condition, is it ?
Alex Sha el 27 de Mzo. de 2024
There are still multi-solutions, even in the range of [0, pi/2], and satisfy the conditions of alpha1<alpha2...<alpha9:
1:
alpha1: 3.91624697106773E-8
alpha2: 0.180888491664553
alpha3: 0.180888491664577
alpha4: 0.346063517935811
alpha5: 0.160265702458496
alpha6: 0.416265628990047
alpha7: 0.630931922206561
alpha8: 1.0471975511966
alpha9: 1.46346318018664
2:
alpha1: 0.203193493585978
alpha2: 0.369672232654069
alpha3: 0.677525318542554
alpha4: 0.844004057610605
alpha5: 1.04719755119661
alpha6: 1.25039104470494
alpha7: 1.25039551959259
alpha8: 1.25039551967021
alpha9: 1.41686978385068
3:
alpha1: 1.19157084434692E-8
alpha2: 0.442501414173056
alpha3: 0.604696137023543
alpha4: 1.0471975511966
alpha5: 1.18529705757435
alpha6: 1.18529705757436
alpha7: 1.34499213444553
alpha8: 1.34499213444553
alpha9: 1.48969896536965
4:
alpha1: 3.47228539110217E-8
alpha2: 0.32285578727148
alpha3: 0.563928125697787
alpha4: 0.563928125697789
alpha5: 0.724341763925112
alpha6: 0.780892412945105
alpha7: 0.780892412945107
alpha8: 1.04719755119659
alpha9: 1.37005333846807
...
further try the range of [0,pi/3], still multi-solutions:
1:
alpha1: 2.45551080796824E-8
alpha2: 2.54044609352637E-8
alpha3: 0.311985704857291
alpha4: 0.311985704857292
alpha5: 0.540750687957892
alpha6: 0.540750687957893
alpha7: 0.786520503128533
alpha8: 0.786520503128533
alpha9: 1.0471975511966
2:
alpha1: 1.95732379177253E-8
alpha2: 2.1556791215656E-8
alpha3: 0.226048467057157
alpha4: 0.226048467057158
alpha5: 0.691609241228221
alpha6: 0.691609241228221
alpha7: 0.85800647331531
alpha8: 0.858006473315311
alpha9: 1.0471975511966
3:
alpha1: 4.12738820583618E-9
alpha2: 6.99668668257787E-9
alpha3: 0.305707153981926
alpha4: 0.305707153981926
alpha5: 0.545459810429233
alpha6: 0.545459810429233
alpha7: 0.841022766210289
alpha8: 0.841022766210289
alpha9: 1.0471975511966
...

Iniciar sesión para comentar.

### Categorías

Más información sobre Newton-Raphson Method en Help Center y File Exchange.

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by