フィルターのクリア

how to create symbolic vector?

49 ビュー (過去 30 日間)
Vicky
Vicky 2013 年 2 月 19 日
コメント済み: Walter Roberson 2019 年 8 月 8 日
hi. im using MATLAB version 7.9.0 (R2009b) and i would like to create symbolic vector. it should go like that: a=sym('a', [1 10]), where second argument means the length of the vector. but it doesnt want to work; error occurs: Formatted arguments cannot be non-scalar numeric matrices. how should i do it/any other way? thank you.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 19 日
v=['[' sprintf('a%d,',1:10)];
v(end)=']'
a=sym(v)
  3 件のコメント
Francesco Giuseppe Fornari
Francesco Giuseppe Fornari 2019 年 8 月 5 日
Hi,
how would you build a vector with groups simbolic of variables?
e.g.
(x1, y1, z1, x2, y2, z2, x3, y3, z3...)
thanks!
Francesco Giuseppe Fornari
Francesco Giuseppe Fornari 2019 年 8 月 5 日
I solved by doing this:
stot=[' '];
for i=1:12
A = i;
s1=sprintf(' x%d, ',A);
s2=sprintf(' y%d, ',A);
s3=sprintf(' z%d ',A);
stot=strcat(stot, s1, s2, s3);
end
Fext1=['[' stot ']'];
Fext=sym(Fext1)
and it was working, but now I get the following message:
Warning: Support of character vectors will be removed in a future release. Character vectors can be used only for variable names and numbers. Instead, to create symbolic expressions first create symbolic variables using 'syms'.To evaluate character vectors and strings representing symbolic expressions, use 'str2sym'.
Doesn't seem to me that str2sym works for what I want...

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2013 年 2 月 19 日
That format for "sym" was not supported until (I think it was) R2011b.
a = sym(zeros(1, 10));
should work, I think.
  1 件のコメント
Vicky
Vicky 2013 年 2 月 19 日
yes, but it creates 0-s... i want symbolic values. thanks, i have done it.

サインインしてコメントする。


Nicola Sacco
Nicola Sacco 2015 年 6 月 19 日
編集済み: Walter Roberson 2019 年 8 月 8 日
Hi everybody,
with reference to Azzi Abdelmalek answer, it is possilbe to generate automatically also the symbolic variables in the vector?
I mean, the code
v=['[' sprintf('a%d,',1:2)];
v(end)=']'
a=sym(v)
produces
a =
[ a1, a2]
but neither a1 or a2 are symbolic variables, althoguh you can perform calcula with them (diff(..,a(1)) is allowed. How to get them without typing
a1 = sym('a1')
I need to assign numeric values to them, after some calculating a Jacobian with results to be something like
J = a1*a2;
Thanks in advance
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 19 日
編集済み: Azzi Abdelmalek 2015 年 6 月 19 日
Is this an answer or a question? If you need to ask a question, post a new one in the section Ask a Question
Walter Roberson
Walter Roberson 2019 年 8 月 8 日
syms(sym('a', [1 2]))
However if you are generating variable names instead of assigning them, then it is bad practice to hard-code the names in expressions such as a1*a2 .

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFunctional Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by