How to create a symbolic matrix with unknown dimensions?

12 views (last 30 days)
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 Comment
John D'Errico
John D'Errico on 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)

Sign in to comment.

Answers (1)

Cam Salzberger
Cam Salzberger on 27 Jun 2017
Edited: Cam Salzberger on 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!