how to create symbolic vector?
显示 更早的评论
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.
采纳的回答
更多回答(2 个)
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.
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
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
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 .
类别
在 帮助中心 和 File Exchange 中查找有关 Functional Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!