Solving trigonometric equations as a optimization problems

k12,k13,k23,k11,k22,k33 are constant and equal
P1a = 400; P2a = -200;P3a = -200;Q1a = 193;Q2a = 96.86;Q3a = -96.86;
P1d = (k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*sin(x(4)*pi/180))+(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*sin(x(5)*pi/180))
P2d = -(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*sin(x(4)*pi/180))+(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*sin((x(5)-x(4))*pi/180))
P3d = -(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*sin(x(5)*pi/180))+(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*sin((x(4)-x(5))*pi/180))
Q1d = (k11.*cos(x(1)*pi/360).*cos(x(1)*pi/360))-(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*cos(x(4)*pi/180))-(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*cos(x(5)*pi/180))
Q2d = -(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*cos(x(4)*pi/180))+(k22.*cos(x(2)*pi/360).*cos(x(2)*pi/360))-(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*cos((x(5)-x(4))*pi/180))
Q3d = -(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*cos(x(5)*pi/180))-(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*cos((x(5)-x(4))*pi/180))+(k33.*cos(x(3)*pi/360).*cos(x(3)*pi/360))
delP1 = (P1d - P1a);
delP2 = (P2d - P2a);
delP3 = (P3d - P3a);
delQ1 = (Q1d - Q1a);
delQ2 = (Q2d - Q2a);
delQ3 = (Q3d - Q3a);
fcost = (((delP1).^2)+((delP2).^2)+((delP3).^2)+((delQ1).^2)+((delQ2).^2)+((delQ3).^2))
the equality constraints: the angles may vary between -180 degree to 180 degree x=fmincon(@cuptpc,x0,a,b)
Hi all, I was trying to solve a set of trigonometric equations taking as a optimization problems to find five unknown variables i.e. angles x(1), x(2), x(3), x(4), x(5). The actual P and Q values are given. The objective is to search for the angles x(1), x(2), x(3), x(4), x(5) that will minimize the cost function by minimizing the Q values. I am getting like this
fcost = 572.8147
x =
-0.0000 28.2228 71.3840 27.8753 29.6215
I am not sure this is the optimum solution for angles or not. I think the cost function should be much smaller than what I am getting. Could anyone please help me with this? Is there any other methods that can be used to solve these equations?

9 comentarios

Shouldn't the arguments in your trigonometric terms be x(i)*pi/180 instead of x(i)*pi/360 ?
Not really. the equations should be as they are.
Could anyone please help me solving these equations? I have written the code for it.
There is no error from the solver - so what shall we do ?
The only thing that comes to mind is to vary the initial guesses for the solution or/and to try a different solver (e.g. fminsearch or lsqnonlin).
Best wishes
Torsten.
Mukul
Mukul el 16 de Mayo de 2018
Editada: Matt J el 16 de Mayo de 2018
% Error using lsqncommon (line 67)
The Levenberg-Marquardt algorithm does not handle bound constraints and the trust-region-reflective algorithm requires at least as
many equations as variables; aborting.
Error in lsqnonlin (line 240)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,caller,...
Error in Optimise_tpc (line 31)
x=lsqnonlin(@cuptpc,x0,a,b)
Trying to slove these equations using Isqnonlin solver but come up with this following error. Could anyone please help me to find out a way for solution?
When using lsqnonlin, you have to return delP1, delP2, delP3, delQ1, delQ2 and delQ3 in "cuptpc", not fcost. Did you do that ?
The is the function
function fcost=cuptpc(x)
L = 22.5e-6;
A1 = 40;
A2 = 40;
A3 = 40;
n=1;
f=20e3;
k11 = (16*A1*A1)/(n^3*(pi)^2*(2*pi*f)*M)
k22 = (16*A2*A2)/(n^3*(pi)^2*(2*pi*f)*M)
k33 = (16*A3*A3)/(n^3*(pi)^2*(2*pi*f)*M)
k12 = (8*A1*A2)/(n^3*(pi)^2*(2*pi*f)*M)
k13 = (8*A1*A3)/(n^3*(pi)^2*(2*pi*f)*M)
k23 = (8*A2*A3)/(n^3*(pi)^2*(2*pi*f)*A)
P1a = 400; P2a = -200;P3a = -200;Q1a = 193;Q2a = 96.86;Q3a = -96.86;
P1d = (k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*sin(x(4)*pi/180))+(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*sin(x(5)*pi/180))
P2d = -(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*sin(x(4)*pi/180))+(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*sin((x(5)-x(4))*pi/180))
P3d = -(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*sin(x(5)*pi/180))+(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*sin((x(4)-x(5))*pi/180))
Q1d = (k11.*cos(x(1)*pi/360).*cos(x(1)*pi/360))-(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*cos(x(4)*pi/180))-(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*cos(x(5)*pi/180))
Q2d = -(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*cos(x(4)*pi/180))+(k22.*cos(x(2)*pi/360).*cos(x(2)*pi/360))-(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*cos((x(5)-x(4))*pi/180))
Q3d = -(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*cos(x(5)*pi/180))-(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*cos((x(5)-x(4))*pi/180))+(k33.*cos(x(3)*pi/360).*cos(x(3)*pi/360))
delP1 = (P1d - P1a);
delP2 = (P2d - P2a);
delP3 = (P3d - P3a);
delQ1 = (Q1d - Q1a);
delQ2 = (Q2d - Q2a);
delQ3 = (Q3d - Q3a);
fcost = (((delP1).^2)+((delP2).^2)+((delP3).^2)+((delQ1).^2)+((delQ2).^2)+((delQ3).^2))
end
and the main program is
a =[ 1 0 0 0 0
-1 0 0 0 0
0 1 0 0 0
0 -1 0 0 0
0 0 1 0 0
0 0 -1 0 0
0 0 0 1 0
0 0 0 -1 0
0 0 0 0 1
0 0 0 0 -1]; %
bb = [180 180 180 180 180 180 90 90 90 90];
b = bb';
x0 = [30 40 35 50 50];
x=lsqnonlin(@cuptpc,x0,a,b)
Now could you please have a look at the code and help getting the it working. or any other alternative ways to solve these equations?
Thank you for your time. I solved it and checked with lsqnonlin and fmincon function that gives the same results for angles.
How can I accept your answer - not getting any options here?
I've moved my last comment to an answer you can accept.
Best wishes
Torsten.

Iniciar sesión para comentar.

 Respuesta aceptada

function fcost=cuptpc(x)
L = 22.5e-6;
A1 = 40;
A2 = 40;
A3 = 40;
n=1;
f=20e3;
M = 1.0; / ????
A = 1.0; % ????
k11 = (16*A1*A1)/(n^3*(pi)^2*(2*pi*f)*M)
k22 = (16*A2*A2)/(n^3*(pi)^2*(2*pi*f)*M)
k33 = (16*A3*A3)/(n^3*(pi)^2*(2*pi*f)*M)
k12 = (8*A1*A2)/(n^3*(pi)^2*(2*pi*f)*M)
k13 = (8*A1*A3)/(n^3*(pi)^2*(2*pi*f)*M)
k23 = (8*A2*A3)/(n^3*(pi)^2*(2*pi*f)*A)
P1a = 400; P2a = -200;P3a = -200;Q1a = 193;Q2a = 96.86;Q3a = -96.86;
P1d = (k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*sin(x(4)*pi/180))+(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*sin(x(5)*pi/180))
P2d = -(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*sin(x(4)*pi/180))+(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*sin((x(5)-x(4))*pi/180))
P3d = -(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*sin(x(5)*pi/180))+(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*sin((x(4)-x(5))*pi/180))
Q1d = (k11.*cos(x(1)*pi/360).*cos(x(1)*pi/360))-(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*cos(x(4)*pi/180))-(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*cos(x(5)*pi/180))
Q2d = -(k12.*cos(x(1)*pi/360).*cos(x(2)*pi/360).*cos(x(4)*pi/180))+(k22.*cos(x(2)*pi/360).*cos(x(2)*pi/360))-(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*cos((x(5)-x(4))*pi/180))
Q3d = -(k13.*cos(x(1)*pi/360).*cos(x(3)*pi/360).*cos(x(5)*pi/180))-(k23.*cos(x(2)*pi/360).*cos(x(3)*pi/360).*cos((x(5)-x(4))*pi/180))+(k33.*cos(x(3)*pi/360).*cos(x(3)*pi/360))
delP1 = (P1d - P1a);
delP2 = (P2d - P2a);
delP3 = (P3d - P3a);
delQ1 = (Q1d - Q1a);
delQ2 = (Q2d - Q2a);
delQ3 = (Q3d - Q3a);
fcost = [delP1 delP2 delP3 delQ1 delQ2 delQ3];
end
and the main program is
lb = [90 90 90 90 90]; % ????
ub = [180 180 180 180 180]; % ????
x0 = [30 40 35 50 50];
x=lsqnonlin(@cuptpc,x0,lb,ub)
Please check the lines with % ???? .
Best wishes
Torsten.

Más respuestas (0)

Etiquetas

Preguntada:

el 14 de Mayo de 2018

Comentada:

el 17 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by