フィルターのクリア

How to create a symbolic matrix with unknown dimensions?

5 ビュー (過去 30 日間)
Álvaro
Álvaro 2017 年 6 月 27 日
編集済み: Cam Salzberger 2017 年 6 月 27 日
Hello,
I would like to create a symbolic matrix of unknown dimensions. My main problem is that if I define a 1x1 symbolic variable and I transpose it, Matlab answers with the same variable (what is logical) instead of transpose(variable).
Thank you in advanced, Álvaro
  1 件のコメント
John D'Errico
John D'Errico 2017 年 6 月 27 日
Matrices in MATLAB don't have an unknown size. But I will point out that MATLAB does know that you transposed a variable.
syms x
x'
ans =
conj(x)

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

回答 (1 件)

Cam Salzberger
Cam Salzberger 2017 年 6 月 27 日
編集済み: Cam Salzberger 2017 年 6 月 27 日
John is right that the complex-conjugate potion of the complex-conjugate transpose (') is retained. However the transpose itself is not:
f = sin(x');
subs(f,x,[1 3])
ans =
[ sin(1), sin(3)]
And nothing happens if you use the non-complex-conjugate transpose (.'):
syms x
x.'
ans =
x
Unfortunately, it doesn't look like there is a way to do this without explicitly specifying the size of the matrix. My advice would be to just give it as large a size as you think it may need, and then just "crop" it when you know how big it actually needs to be (whether inside this function or outside of it).
If you can give us more details on your code though, we may be able to suggest how to create the variables correctly the first time. For example, if you're writing code that does something like this:
function y = A_tranpose_times_x(x)
syms A
y = A.'*x;
You could instead do:
function y = A_transpose_times_x(x)
A = sym('A',[size(x,1),2]);
y = A.'*x;
-Cam

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by