How can i define a m by n symbolic matrix?

4 views (last 30 days)
ba sa
ba sa on 19 Nov 2021
Edited: the cyclist on 19 Nov 2021
I know how to for example define a 3 by 4 symbolic matrix with this:
x=sym('a',[3,4])
but I don't know how to define this:
x=sym('a',[m n])
(m and n aren't variables,i just want to get something like
a11 a12 ... a1n
. . .
. . .
am1 am2 ... amn

Accepted Answer

John D'Errico
John D'Errico on 19 Nov 2021
Edited: John D'Errico on 19 Nov 2021
If m and n are themselves symbolic, you cannot do so. However, you can do this:
matfun = @(m,n) sym('a',[m,n]);
Now you can use it to create a matrix of any desired size. Thus
matfun(2,3)
ans = 
matfun(4,1)
ans = 
But you cannot create something of indeterminate size or dimensions.
Could you write your own class of objects, that do as you wish? Well, yes. I suppose you could. I'm not sure what value it would offer, but you would need to write the code to do so yourself. And as well, you would then need to write code to manipiulate those objects, as MATLAB will not automatically know how to multiply such objects without your explicit direction.
  1 Comment
ba sa
ba sa on 19 Nov 2021
Thanks, very helpful
I'm trying to find a way to convert a matrix to rref, and well I wanted to use a m by n matrix for the function
also I have another question,the code I've written so far is like this:
function b= RREF_GEN (X,M,N)
X1=X(M-(M-1),:,1,:)-(X(M-(M-1),:,1)/X(1,(N-(N-1))))*X(1,1,:);
X2=X1(M-(M-2):M,1:N)-(X1(M-(M-2):M,1)/X1(1,N-(N-2)))*X(1,1,:);
I know I have to somehow "automate" the (M-(M-1)) and (N-(N-1)) process
any ideas on that?

Sign in to comment.

More Answers (1)

the cyclist
the cyclist on 19 Nov 2021
Edited: the cyclist on 19 Nov 2021
Matrices where the size is not predetermined cannot be defined in MATLAB. Source: this question/answer and the one it points to.
What is your use case? Maybe there is another way to do what you need.

Tags

Products

Community Treasure Hunt

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

Start Hunting!

Translated by