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 个评论

Please would you delete the four duplicates of this question. Thanks.

请先登录,再进行评论。

 采纳的回答

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 个评论

thank you very much,i never forget your help;-)
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] );
>>
I do not know which version the ability to use a format with sym() came in. Which version are you running ?

请先登录,再进行评论。

更多回答(2 个)

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 个评论

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
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.
no i just ask for matlab program,but any way thanks for your care;-)

请先登录,再进行评论。

I think you need the Symbolic Math Toolbox.

1 个评论

thanks i think my problem is solve by WALTER suggestion,but thanks for your care you have;-)

请先登录,再进行评论。

类别

Community Treasure Hunt

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

Start Hunting!

Translated by