Define an array using symbolic variable as size parameter.
显示 更早的评论
Hello All,
Is it possible to generate an array or matrix using a symbolic variable as a size for a matrix, I want to define a array of symbolic variables who's size is unknown to me. I mean, it is required for me to define the size as a symbolic variable but I can't do it.here is 1 example that I tried:
syms N;
q_t = sym('q_t', [1,N]);
I am getting an error saying 'strcmp' is not defined for variable of class sym variables.
Can anyone help?
Thank you all in advance.
回答(1 个)
Walter Roberson
2011-10-17
0 个投票
7 个评论
Alok
2011-10-17
Alok
2011-10-17
Alok
2011-10-17
Alok
2011-10-17
Walter Roberson
2011-10-17
MuPAD has no way to represent arrays of symbols where the array limits are not fixed.
You probably need to be writing MuPAD procedures, where N is a specific (numeric) size that is passed in to the procedure.
Alok
2011-10-17
Walter Roberson
2011-10-17
I do not know enough about MuPAD to say whether it is somehow possible to do what you ask.
I do know enough about MuPAD to know that it would at least be very messy to do what you ask.
I recommend that you instead define *procedures* that return the values you want. Or possibly that you use a MuPAD and override its "slots" so that it has the indexing behavior and other behaviors that you want.
Whatever expressions you produce are going to be full of piecewise() statements. For example if you assign q_t[1] and then you assign q_t[N] with N symbolic, then q_t[1] would have to get transformed into a piecewise() that tested N<>1 and returned the first value assigned if so, but in the otherwise where N==1, returned the second value assigned. Also, every single assignment in to q_t you made would have to be protected by a test that when N is eventually instantiated, that it has a positive integral value, because q_t[1] has to generate a failure if you eventually decide that you want N to be instantiated as as -17.3432 . I don't know what the array elements should evaluate to if you decide that N should be instantiated as (infinity intersect DOM_INTEGER) ... the normal infinity is the Real infinity not the integer infinity...
类别
在 帮助中心 和 File Exchange 中查找有关 Common Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!