Define an array using symbolic variable as size parameter.

6 views (last 30 days)
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.

Answers (1)

Walter Roberson
Walter Roberson on 17 Oct 2011
Please see this previous Question
  7 Comments
Alok
Alok on 17 Oct 2011
actually I am designing a solver for my robot and assuming that it can have N degree of freedom, so eventually YES, I will pass the value of N, but in general I want to create for N variables.in order to make my solver more robust 1, is it possible somehow ?
Walter Roberson
Walter Roberson on 17 Oct 2011
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...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!