How can i define a m by n symbolic matrix?

2 views (last 30 days)
I know how to for example define a 3 by 4 symbolic matrix with this:
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
ans = 
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)
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.



Community Treasure Hunt

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

Start Hunting!

Translated by