Summation in a for loop of a function
Show older comments
Hi everyone! I need to write a function for ode45 solver, but the results I'm getting are wrong. What i need to get is a system of ODEs. To do so i prepared something like this:
function dndt = fun(t,n)
global v
%v is defined in another file
dndt = zeros(numel(v),1);
for i = 1 : numel(v) - 1
dndt(i) = sum(n(i : numel(v))) * v(i+1) - v(i) * n(i);
end
end
Now, my question is: sum(n(i : numel(v))) should be the summation of n(k) with k going from i to number of intervals. Is it correct to write it like that? Or should I introduce another for loop to solve that summation? Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB 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!