Filter löschen
Filter löschen

How to create a symbolic matrix with unknown dimensions?

5 Ansichten (letzte 30 Tage)
Álvaro
Álvaro am 27 Jun. 2017
Bearbeitet: Cam Salzberger am 27 Jun. 2017
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 Kommentar
John D'Errico
John D'Errico am 27 Jun. 2017
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)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cam Salzberger
Cam Salzberger am 27 Jun. 2017
Bearbeitet: Cam Salzberger am 27 Jun. 2017
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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by