Resolution of a system with sine and cosine terms

1 visualización (últimos 30 días)
Andrea Cesaro
Andrea Cesaro el 17 de Jul. de 2023
Comentada: Andrea Cesaro el 13 de Ag. de 2023
I write a code like this, but the run continues indefinitely; it seems that Matlab is not able to solve this system. Is that really the case or am I wrong somewhere?
clc
clear
close all
syms phi1
syms theta1
syms phi2
syms theta2
syms phi3
syms theta3
syms phi4
syms theta4
ro = sqrt(3);
csi1 = ro*sin(phi1)*cos(theta1);
eta1 = ro*sin(phi1)*sin(theta1);
zeta1 = ro*cos(phi1);
csi2 = ro*sin(phi2)*cos(theta2);
eta2 = ro*sin(phi2)*sin(theta2);
zeta2 = ro*cos(phi2);
csi3 = ro*sin(phi3)*cos(theta3);
eta3 = ro*sin(phi3)*sin(theta3);
zeta3 = ro*cos(phi3);
csi4 = ro*sin(phi4)*cos(theta4);
eta4 = ro*sin(phi4)*sin(theta4);
zeta4 = ro*cos(phi4);
eqns = [csi1^2 + csi2^2 + csi3^2 + csi4^2 == 4, eta1^2 + eta2^2 + eta3^2 + eta4^2 == 4, zeta1^2 + zeta2^2 + zeta3^2 + zeta4^2 == 4, csi1*eta1 + csi2*eta2 + csi3*eta3 + csi4*eta4 == 0, eta1*zeta1 + eta2*zeta2 + eta3*zeta3 + eta4*zeta4 == 0, zeta1*csi1 + zeta2*csi2 + zeta3*csi3 + zeta4*csi4 == 0, csi1 + csi2 + csi3 + csi4 == 0, eta1 + eta2 + eta3 + eta4 == 0, zeta1 + zeta2 + zeta3 + zeta4 == 0,...
theta1>0, theta1<2*pi, phi1>0, phi1<pi, theta2>0, theta2<2*pi, phi2>0, phi2<pi, theta3>0, theta3<2*pi, phi3>0, phi3<pi, theta4>0, theta4<2*pi, phi4>0, phi4<pi];
[phi1, theta1, phi2, theta2, phi3, theta3, phi4, theta4] = solve(eqns, [phi1, theta1, phi2, theta2, phi3, theta3, phi4, theta4]);
  4 comentarios
Andrea Cesaro
Andrea Cesaro el 17 de Jul. de 2023
Ok thank you, but although I add ro like an other unknown Matlab is not able to solve it
Andrea Cesaro
Andrea Cesaro el 17 de Jul. de 2023
Like this:
clc
clear
close all
syms phi1
syms theta1
syms phi2
syms theta2
syms phi3
syms theta3
syms phi4
syms theta4
syms ro
csi1 = ro*sin(phi1)*cos(theta1);
eta1 = ro*sin(phi1)*sin(theta1);
zeta1 = ro*cos(phi1);
csi2 = ro*sin(phi2)*cos(theta2);
eta2 = ro*sin(phi2)*sin(theta2);
zeta2 = ro*cos(phi2);
csi3 = ro*sin(phi3)*cos(theta3);
eta3 = ro*sin(phi3)*sin(theta3);
zeta3 = ro*cos(phi3);
csi4 = ro*sin(phi4)*cos(theta4);
eta4 = ro*sin(phi4)*sin(theta4);
zeta4 = ro*cos(phi4);
eqns = [csi1^2 + csi2^2 + csi3^2 + csi4^2 == 4, eta1^2 + eta2^2 + eta3^2 + eta4^2 == 4, zeta1^2 + zeta2^2 + zeta3^2 + zeta4^2 == 4, csi1*eta1 + csi2*eta2 + csi3*eta3 + csi4*eta4 == 0, eta1*zeta1 + eta2*zeta2 + eta3*zeta3 + eta4*zeta4 == 0, zeta1*csi1 + zeta2*csi2 + zeta3*csi3 + zeta4*csi4 == 0, csi1 + csi2 + csi3 + csi4 == 0, eta1 + eta2 + eta3 + eta4 == 0, zeta1 + zeta2 + zeta3 + zeta4 == 0,...
theta1>0, theta1<2*pi, phi1>0, phi1<pi, theta2>0, theta2<2*pi, phi2>0, phi2<pi, theta3>0, theta3<2*pi, phi3>0, phi3<pi, theta4>0, theta4<2*pi, phi4>0, phi4<pi];
[phi1, theta1, phi2, theta2, phi3, theta3, phi4, theta4, ro] = solve(eqns, [phi1, theta1, phi2, theta2, phi3, theta3, phi4, theta4, ro]);

Iniciar sesión para comentar.

Respuesta aceptada

Dheeraj
Dheeraj el 10 de Ag. de 2023
Hi,
If the script is running for a long time without producing results, it's possible that the symbolic solver is struggling to find a solution due to the complexity of the equations or the constraints. Few ways you could work around to solve the problem are,
  1. Simplifying the equations or by breaking down the problem to subproblems and solve them separately and try to combine the results at the end.
  2. Using MATLAB parallel computing toolbox to speed up calculations. You may refer to this document on parallel computing for better understanding. https://in.mathworks.com/help/parallel-computing/getting-started-with-parallel-computing-toolbox.html
  2 comentarios
John D'Errico
John D'Errico el 10 de Ag. de 2023
Yes. Note also that inequalities are difficult things to handle, and there are MANY of them here.
Andrea Cesaro
Andrea Cesaro el 13 de Ag. de 2023
Thank you very much

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by