How to solve an equation with two matrices?

1 回表示 (過去 30 日間)
Jimmy Neutron
Jimmy Neutron 2021 年 12 月 13 日
回答済み: Gargi Patil 2021 年 12 月 21 日
I am trying to solve for all the unknowns in a matrix where I know the output of the matrix. This is what I mean: I have X and A and based on the two I want to find theta1 alpha d a
syms theta1 alpha d a
X = [ nan nan -3/4 1;
nan 1/4 nan sqrt(3);
0 nan nan 1/3;
0 0 0 1]
A = [ cos(theta1) -sin(theta1)*cos(alpha) sin(theta1)*sin(alpha) a*cos(theta1);
sin(theta1) cos(theta1)*cos(alpha) -cos(theta1)*sin(alpha) a*sin(theta1);
0 sin(alpha) cos(alpha) d;
0 0 0 1]
idx = find(~isnan(X));
solve(X(idx)==A(idx), [ theta1 alpha d a])
  3 件のコメント
Jimmy Neutron
Jimmy Neutron 2021 年 12 月 13 日
I get the output theta1 =theta1, alpha=alpha, d=d and a=a...
Torsten
Torsten 2021 年 12 月 13 日
S = solve(X(idx)==A(idx), [ theta1 alpha d a])
What is the MATLAB class of S ?

サインインしてコメントする。

回答 (1 件)

Gargi Patil
Gargi Patil 2021 年 12 月 21 日
Hi,
As suggested in the comments, the result can be stored in a variable S. S will be a struct with the fields theta1, alpha, d and a as shown below:
syms theta1 alpha d a
X = [ nan nan -3/4 1;
nan 1/4 nan sqrt(3);
0 nan nan 1/3;
0 0 0 1];
A = [ cos(theta1) -sin(theta1)*cos(alpha) sin(theta1)*sin(alpha) a*cos(theta1);
sin(theta1) cos(theta1)*cos(alpha) -cos(theta1)*sin(alpha) a*sin(theta1);
0 sin(alpha) cos(alpha) d;
0 0 0 1];
idx = find(~isnan(X));
S = solve(X(idx)==A(idx), [theta1 alpha d a])
S = struct with fields:
theta1: [2×1 sym] alpha: [2×1 sym] d: [2×1 sym] a: [2×1 sym]
You can access the possible solutions as follows:
S.a(:, 1)
ans = 

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by