Creating vector of symbols
12 次查看(过去 30 天)
显示 更早的评论
For example, A = sym('A%d%d', [3 3]) generates the 3-by-3 symbolic matrix A with the elements A11, A12, ..., A33
0 个评论
采纳的回答
Walter Roberson
2011-3-4
编辑:Walter Roberson
2017-2-22
For example, for a P x Q x R matrix,
[x,y,z]=ndgrid(1:P,1:Q,1:R);
A = sym( reshape( ...
cellfun(@sym, ...
strcat('A', ...
cellstr(num2str(x(:))), ...
cellstr(num2str(y(:))), ...
cellstr(num2str(z(:)))), ...
'Uniform', 0), ...
P, Q, R ) );
The code is not as long as it looks; I formatted it for display purposes.
Trim to two dimensions or expand to the number of dimensions needed.
4 个评论
Karan Gill
2017-3-2
No, >2 dim works in R2016a (unless I misunderstand you).
>> A = sym('A', [2 2 2])
A(:,:,1) =
[ A1_1_1, A1_2_1]
[ A2_1_1, A2_2_1]
A(:,:,2) =
[ A1_1_2, A1_2_2]
[ A2_1_2, A2_2_2]
Walter Roberson
2017-3-2
Ah, then I think that advance is best left as a comment rather than by editing the response which was appropriate for the time it was written and continues to be required by people using older versions.
更多回答(3 个)
Brian
2011-3-4
3 个评论
Walter Roberson
2011-3-4
It does appear that supplying a size is a new feature as of 2010b; the 2010a documentation does not show it.
http://www.mathworks.com/help/releases/R2010a/toolbox/symbolic/sym.html
Paulo Silva
2011-3-4
A=[3 3]; %create any numeric vector or matrix
A=sym(A) %convert it to symbolic
A=double(A) %convert it back to numeric (double in this case)
2 个评论
Paulo Silva
2011-3-4
One thing you should always have open in your matlab is the Workspace window so you can see what variables are create and their details, other ways is to do
class(A) or in the case of your small code class(ans).
In a way they can, that small code of yours gives the ans=2 but it's a symbolic response not numeric. My1=sym('1'); 2*My1 gives ans=2, again it's a symbolic value. There are other ways to make symbolic values but you should look first in your documentation.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!