Serial summation within a for() loop

Summation Equations are a particular Achilles' Heel for me plus I'm a bit rusty on MATLAB these days. How I can algorithmize this equation?
where Δt_sup, q and t are each vector arrays. I was given this expansion as an example for Δt_sup(3):
Now I know that I need to do this within a for loop to iterate values for each corresponding value of Δt_sup(i), q(i) and t(i), but I'm not sure how to go about tackling this beyond the basic setup as such:
t_sup=zeros(length(q),1);
for i=1:length(q)
t_sup(i)= ???
end
Any help would be much appreciated.

1 Comment

You could use another for-loop within the for-loop which runs from 1 to i and adds the actual j-value in each step:
t_sup(i) = t_sup(i) + ((q(j) - q(j-1))/q(i))*log(t(i)-t(j-1)); % Caution: log10 for log to the base 10, log is for base e

Sign in to comment.

Answers (1)

You might not need any loops. See if this works:
q = randi(99, 10, 1); % Create Data (Column Vector)
t = [1:10]'; % Create Data (Column Vector)
dq = [diff(q); q(1)]/q(end); % ‘q-difference’ Vector
dt = [(t(end)-t(1:end-1)); t(end)]; % ‘t-difference’ Vector
Dt_sup = sum(dq .* log(dt)); % Δt_sup

2 Comments

Correct me if my understanding of what your script does is off, but I think I still need a for loop as I need to be able to find a value for Dt_sup at each time t and this script results with a scalar value for Dt_sup.
My code calculates ‘Dt_sup’ for equal-length vectors of ‘t’ and ‘q’ defined in the code. My understanding of your code is that it is a scalar for given equal-length vectors of ‘t’ and ‘q’. It does not appear to be a function of ‘t’ otherwise. You can certainly loop through it with different vectors for ‘t’ and ‘q’, the only restriction being that the ‘t’ vector must be strictly monotonically increasing.
I just took the equation in your Question and coded it as presented. I have no idea what you’re doing, or the larger context of this equation.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Asked:

on 19 Oct 2015

Commented:

on 20 Oct 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!