Solving trigonometric simultaneous equations

6 visualizaciones (últimos 30 días)
Jupin Sat
Jupin Sat el 23 de Mayo de 2017
Respondida: Anurag Ojha el 18 de Ag. de 2024
Is it possible to solve when the equations are little complex? For example lets's take an inverse kinematics problem. Where we get,
-0.2595 0.5536 0.7913 0.3004 r11 r12 r13 o1
-0.7781 -0.6052 0.1682 0.0639 = r21 r22 r23 o2
0.5721 -0.5721 0.5878 0.6167 r31 r32 r33 o3
0 0 0 1 0 0 0 0
each of these symbols represents a trigonometric function such as below. Need to find θ1,θ2,θ3,θ4,θ5
[ sin(theta1)*sin(theta5) - cos(theta5)*(cos(theta4)*(cos(theta1)*sin(theta2)*sin(theta3) - cos(theta1)*cos(theta2)*cos(theta3)) + sin(theta4)*(cos(theta1)*cos(theta2)*sin(theta3) + cos(theta1)*cos(theta3)*sin(theta2))), cos(theta5)*sin(theta1) + sin(theta5)*(cos(theta4)*(cos(theta1)*sin(theta2)*sin(theta3) - cos(theta1)*cos(theta2)*cos(theta3)) + sin(theta4)*(cos(theta1)*cos(theta2)*sin(theta3) + cos(theta1)*cos(theta3)*sin(theta2))), cos(theta4)*(cos(theta1)*cos(theta2)*sin(theta3) + cos(theta1)*cos(theta3)*sin(theta2)) - sin(theta4)*(cos(theta1)*sin(theta2)*sin(theta3) - cos(theta1)*cos(theta2)*cos(theta3)), (1143*cos(theta1)*cos(theta2))/5000 + (127*cos(theta4)*(cos(theta1)*cos(theta2)*sin(theta3) + cos(theta1)*cos(theta3)*sin(theta2)))/1600 - (127*sin(theta4)*(cos(theta1)*sin(theta2)*sin(theta3) - cos(theta1)*cos(theta2)*cos(theta3)))/1600 - (1143*cos(theta1)*sin(theta2)*sin(theta3))/5000 + (1143*cos(theta1)*cos(theta2)*cos(theta3))/5000]
[ - cos(theta1)*sin(theta5) - cos(theta5)*(cos(theta4)*(sin(theta1)*sin(theta2)*sin(theta3) - cos(theta2)*cos(theta3)*sin(theta1)) + sin(theta4)*(cos(theta2)*sin(theta1)*sin(theta3) + cos(theta3)*sin(theta1)*sin(theta2))), sin(theta5)*(cos(theta4)*(sin(theta1)*sin(theta2)*sin(theta3) - cos(theta2)*cos(theta3)*sin(theta1)) + sin(theta4)*(cos(theta2)*sin(theta1)*sin(theta3) + cos(theta3)*sin(theta1)*sin(theta2))) - cos(theta1)*cos(theta5), cos(theta4)*(cos(theta2)*sin(theta1)*sin(theta3) + cos(theta3)*sin(theta1)*sin(theta2)) - sin(theta4)*(sin(theta1)*sin(theta2)*sin(theta3) - cos(theta2)*cos(theta3)*sin(theta1)), (1143*cos(theta2)*sin(theta1))/5000 + (127*cos(theta4)*(cos(theta2)*sin(theta1)*sin(theta3) + cos(theta3)*sin(theta1)*sin(theta2)))/1600 - (127*sin(theta4)*(sin(theta1)*sin(theta2)*sin(theta3) - cos(theta2)*cos(theta3)*sin(theta1)))/1600 - (1143*sin(theta1)*sin(theta2)*sin(theta3))/5000 + (1143*cos(theta2)*cos(theta3)*sin(theta1))/5000]
[ cos(theta5)*(cos(theta4)*(cos(theta2)*sin(theta3) + cos(theta3)*sin(theta2)) + sin(theta4)*(cos(theta2)*cos(theta3) - sin(theta2)*sin(theta3))), -sin(theta5)*(cos(theta4)*(cos(theta2)*sin(theta3) + cos(theta3)*sin(theta2)) + sin(theta4)*(cos(theta2)*cos(theta3) - sin(theta2)*sin(theta3))), sin(theta4)*(cos(theta2)*sin(theta3) + cos(theta3)*sin(theta2)) - cos(theta4)*(cos(theta2)*cos(theta3) - sin(theta2)*sin(theta3)), (1143*sin(theta2))/5000 + (1143*cos(theta2)*sin(theta3))/5000 + (1143*cos(theta3)*sin(theta2))/5000 - (127*cos(theta4)*(cos(theta2)*cos(theta3) - sin(theta2)*sin(theta3)))/1600 + (127*sin(theta4)*(cos(theta2)*sin(theta3) + cos(theta3)*sin(theta2)))/1600 + 4953/20000]
[ 0, 0, 0, 1]
Is matlab capable of solving such equations?
Thank you.

Respuestas (1)

Anurag Ojha
Anurag Ojha el 18 de Ag. de 2024
Hello Jupin
Yes, MATLAB is capable of solving complex equations, including inverse kinematics problems. MATLAB provides powerful numerical computation capabilities and has built-in functions for solving systems of equations. In this case, you can use the fsolve function to find the values of θ1, θ2, θ3, θ4, and θ5 that satisfy the given equations.
I have taken a simple example to demostrate. Kindly make changes as per your use case:
% Define the function to solve
function F = trigEquations(theta)
% Unpack the angles
theta1 = theta(1);
theta2 = theta(2);
% Equations to solve
F(1) = sin(theta1) + cos(theta2) - 1.5;
F(2) = cos(theta1) + sin(theta2) - 0.5;
end
% Initial guess for the angles
initial_guess = [0, 0];
% Use fsolve to solve the equations
options = optimoptions('fsolve', 'Display', 'iter');
[theta_solution, fval] = fsolve(@trigEquations, initial_guess, options);
Norm of First-order Trust-region Iteration Func-count ||f(x)||^2 step optimality radius 0 3 0.5 0.5 1 1 6 0.0308187 0.707107 0.158 1 2 9 0.000169659 0.175552 0.0122 1.77 3 12 8.38458e-09 0.0140895 8.57e-05 1.77 4 15 2.10737e-17 9.97403e-05 4.28e-09 1.77 Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
% Display the results
fprintf('Solution for theta1: %.4f radians\n', theta_solution(1));
Solution for theta1: 0.5900 radians
fprintf('Solution for theta2: %.4f radians\n', theta_solution(2));
Solution for theta2: -0.3373 radians
Adding the documentation to get better understanding:

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by