- ‘solve’ function: https://www.mathworks.com/help/symbolic/sym.solve.html
- Solve system of Linear Equations: https://www.mathworks.com/help/symbolic/solve-a-system-of-linear-equations.html
How to solve a linear systems with 3 variables
5 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
When I run my code, I'm having some issues in the line:
[theta1,theta2,theta3] = solve([X==x,Y==y,Z==z],[theta1 theta2 theta3])
The line is giving me a warning message (unable to find explicit solution) and the results are "Empty sym: 0-by-1"
How would I put this into matlab and solve it . Sorry for what is probably such a simple question, but I have days figuring out how to solve it. Thanks for your help.
La = 4;
Lb = 10;
Lc = 12;
syms theta1 theta2 theta3 X Y Z
assume(X, 'Real');
assume(Y, 'Real');
assume(Z, 'Real');
ParamAngular = [theta1 La 0 90; theta2 0 Lb 0; theta3 0 Lc 0];
ParamTableAngular = DHTable(eval(ParamAngular))
[theta1,theta2,theta3] = solve([X==x,Y==y,Z==z],[theta1 theta2 theta3])
function [ParameterTable] = DHTable(Matrix)
Matrix = string(Matrix);
Theta = Matrix(:,1);
d = Matrix(:,2);
a = Matrix(:,3);
Alpha = Matrix(:,4);
ParameterTable = table(Theta,d,a,Alpha);
end
function [X,Y,Z] = DHEquations(ParameterTable)
Temp = eye(4);
A =@(theta,d,a,alpha) [cosd(theta) -cosd(alpha)*sind(theta) sind(alpha)*sind(theta) a*cosd(theta);
sind(theta) cosd(alpha)*cosd(theta) -sind(alpha)*cosd(theta) a*sind(theta);
0 sind(alpha) cosd(alpha) d;
0 0 0 1];
[L,~] = size(ParameterTable);
for i = 1:L
theta = ParameterTable(i,1);
d = ParameterTable(i,2);
a = ParameterTable(i,3);
alpha = ParameterTable(i,4);
Temp = Temp * A(theta,d,a,alpha);
end
X = simplify(Temp(1,4));
Y = simplify(Temp(2,4));
Z = simplify(Temp(3,4));
end
0 个评论
回答(1 个)
Raj
2023-10-1
Hi Erick,
I understand that you are facing issues to solve a linear system with 3 variables.
I tried reproducing the error through the code you sent and observed that the compiler is not able to recognize variables ‘x’,’y’,’z’. Maybe you should check and try rectifying this.
Additionally I would like to point out inside solve function
[y1,...,yN] = solve(eqns,vars)
The ‘eqns’ refers to the system of equations, specified as symbolic expressions or symbolic equations. If any elements of ‘eqns’ are symbolic expressions (without the right side), ‘solve’ equates the element to 0. Kindly verify the equation and match it with the equation you are trying to solve.
For more information on this refer the following:
I hope this resolves your query!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!