How can i define a m by n symbolic matrix?

2 次查看(过去 30 天)
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

采纳的回答

John D'Errico
John D'Errico 2021-11-19
编辑:John D'Errico 2021-11-19
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 个评论
ba sa
ba sa 2021-11-19
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?

请先登录,再进行评论。

更多回答(1 个)

the cyclist
the cyclist 2021-11-19
编辑:the cyclist 2021-11-19
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.

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by