undefined variable, passive variable vector

HELLO do you know how should i make vector with passiv variable.and be aware of that the size of this vector will be defined in the middel of program. thanks

1 comentario

David Young
David Young el 1 de Mzo. de 2011
Please would you delete the four duplicates of this question. Thanks.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de Mzo. de 2011

1 voto

See the documentation for sym and in particular this part:
A = sym('A', [m n]) creates a m-by-n matrix of symbolic variables. The dimensions m and n of a matrix must be integers. You can use this syntax to create a 1-by-n or an n-by-1 vector. The sym function does not allow you to use symbolic variables without assigned numeric values as dimensions. By default, the generated names of elements of a vector use the form Ak, and the generated names of elements of a matrix use the form Ai_j. The base, A, must be a valid variable name. (To verify whether the name is a valid variable name, use isvarname). The values of k, i, and j range from 1 to m or 1 to n. To specify other form for generated names of matrix elements, use '%d' in the first input. For example, A = sym('A%d%d', [3 3]) generates the 3-by-3 symbolic matrix A with the elements A11, A12, ..., A33

3 comentarios

kaveh
kaveh el 3 de Mzo. de 2011
thank you very much,i never forget your help;-)
kaveh
kaveh el 3 de Mzo. de 2011
sorry for disturbing you again
i write as you said but i got this error:
??? Error using ==> sym.sym>char2sym at 414
Not a valid symbolic expression.
Error in ==> sym.sym at 95
S = char2sym(x);
Error in ==> Untitled at 4
A=sym('A%d%d', [4 3] );
>>
Walter Roberson
Walter Roberson el 3 de Mzo. de 2011
I do not know which version the ability to use a format with sym() came in. Which version are you running ?

Iniciar sesión para comentar.

Más respuestas (2)

David Young
David Young el 1 de Mzo. de 2011
In MATLAB, you probably don't need to make the vector before you know its size. You don't have to declare variables, so the best solution is probably to simply not use the vector until the point where the size is known.
If there's some reason you need to reference the variable before that point, you could set it to the empty matrix:
v = [];
to indicate that it's a vector with, as yet, no contents.

3 comentarios

kaveh
kaveh el 1 de Mzo. de 2011
sorry ,i think i Express bad my question.
i mean:
i need vector for exampel [x1 x2 ... xn]
to multiplication it to another matrix
then i have matrix with arrays that have Unknown variable and i have some equation in every line of answer matrix
David Young
David Young el 2 de Mzo. de 2011
Can I just check - are you asking about the Symbolic Math Toolbox, as Kaustubha govind suggests? If you are, then sorry, I misunderstood. I don't know about that toolbox, and I hope someone else can help.
kaveh
kaveh el 3 de Mzo. de 2011
no i just ask for matlab program,but any way thanks for your care;-)

Iniciar sesión para comentar.

Kaustubha Govind
Kaustubha Govind el 1 de Mzo. de 2011

1 voto

I think you need the Symbolic Math Toolbox.

1 comentario

kaveh
kaveh el 3 de Mzo. de 2011
thanks i think my problem is solve by WALTER suggestion,but thanks for your care you have;-)

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by