Use sym to define a sum function, but i have a problem with indexing
Show older comments
% Define N(r)
c = [-1*ones(3,1); 0.3*ones(5,1); 0.6*ones(6,1)];
n = length(c);
syms k r
f = c(k)/(1+r)^(k-1);
V = subs(f, k, 1:n);
S_sum = sum(V);
Apparently Matlab gives me this problem when I tried to use elements in array c, e.g. c(1) to c(k)
Error using sym/subsindex (line 836)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments
must be symbolic variables, and function body must be sym expression.
How should I fix this index problem?
Thank you!
1 Comment
Yihan Hu
on 8 Dec 2018
Accepted Answer
More Answers (1)
madhan ravi
on 8 Dec 2018
syms r
k=1:n;
f = c(k)./(1+r).^(k-1);
S_sum=vpa(symsum(f),2);
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!