a question of assigning the list elements
1 次查看(过去 30 天)
显示 更早的评论
i just want to assign the
m(0)=1;
m(1)=1;
m(2)=1;
and get the sum of them,but when i assign them,the matlab can't get the answer,and why?
syms s1;
syms m(k);
syms z(k);
m(0)=1;
m(1)=1;
m(2)=1;
s1=symsum(m(k),k,0,2)
0 个评论
回答(2 个)
KSSV
2018-12-20
m = [1 1 1] ;
iwant = sum(m) ;
2 个评论
KSSV
2018-12-20
Remember matlab index starts from 1...the index should be always positive.
m(0)=1;
m(1)=1;
m(2)=1;
The above is same as:
m = [1 1 1] ;
The above step is short, effective. You can access the elements using:
m(1)
m(2)
m(3)
MATLAB is very effificent and simple.
madhan ravi
2018-12-20
why? the below works because the right side should be a symbolic object to perform the operation you need
syms m(k)
m(k)=k
symsum(m(k),k,0,2)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!