Solve system of equations with the symbolic matrix

4 ビュー (過去 30 日間)
Cengizhan Demirbas
Cengizhan Demirbas 2021 年 2 月 26 日
コメント済み: Cengizhan Demirbas 2021 年 2 月 26 日
I have a 4x4 matrix T, and I know its last row to be [0 0 0 1]. I also know these equations:
After solving these by hand, I find that third column has no solution (except for [4,3], which i know to be 0).
My question is how can I keep these unsolved variables symbolic while solving the system?
I tried the following code:
T = sym('x', [4 4]);
T(4,:) = [0 0 0 1];
T
p_new1 = [2 0 0 1].';
p_old1 = [0 0 0 1].';
p_new2 = [3 0 0 1].';
p_old2 = [1 0 0 1].';
p_new3 = [2 0 1 1].';
p_old3 = [0 1 0 1].';
eqn1 = p_new1 == T*p_old1;
eqn2 = p_new2 == T*p_old2;
eqn3 = p_new3 == T*p_old3;
sol = solve([eqn1, eqn2, eqn3])
This results in a strut with 9 elements that are solved. It completely excludes third column which i want to remain symbolic like x13 x23 x33. How can I do this?

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 26 日
T = sym('x', [4 4]);
T(4,:) = [0 0 0 1];
T
T = 
p_new1 = [2 0 0 1].';
p_old1 = [0 0 0 1].';
p_new2 = [3 0 0 1].';
p_old2 = [1 0 0 1].';
p_new3 = [2 0 1 1].';
p_old3 = [0 1 0 1].';
eqn1 = p_new1 == T*p_old1;
eqn2 = p_new2 == T*p_old2;
eqn3 = p_new3 == T*p_old3;
s = solve([eqn1, eqn2, eqn3], reshape(T(1:3,[1:2,4]),1,[]))
s = struct with fields:
x1_1: [1×1 sym] x2_1: [1×1 sym] x3_1: [1×1 sym] x1_2: [1×1 sym] x2_2: [1×1 sym] x3_2: [1×1 sym] x1_4: [1×1 sym] x2_4: [1×1 sym] x3_4: [1×1 sym]
subs(T,s)
ans = 
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 26 日
T = sym('x', [4 4]);
T(4,:) = [0 0 0 1];
T
T = 
p_new1 = [2 0 0 1].';
p_old1 = [0 0 0 1].';
p_new2 = [3 0 0 1].';
p_old2 = [1 0 0 1].';
p_new3 = [2 0 1 1].';
p_old3 = [0 1 0 1].';
eqn1 = p_new1 == T*p_old1;
eqn2 = p_new2 == T*p_old2;
eqn3 = p_new3 == T*p_old3;
M = [eqn1, eqn2, eqn3]
M = 
s = solve(M)
s = struct with fields:
x1_1: [1×1 sym] x1_2: [1×1 sym] x1_4: [1×1 sym] x2_1: [1×1 sym] x2_2: [1×1 sym] x2_4: [1×1 sym] x3_1: [1×1 sym] x3_2: [1×1 sym] x3_4: [1×1 sym]
subs(T,s)
ans = 
You can see here that I didn't have to do anything special -- solve() automatically worked it out in terms of variables actually present, and subs() back into T is enough to get nice matrix form.
But if you want more certainty:
vars = symvar(M);
[A,b] = equationsToMatrix(M, vars)
A = 
b = 
vars(:) == A\b
ans = 
Cengizhan Demirbas
Cengizhan Demirbas 2021 年 2 月 26 日
Thanks!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by