Serial summation within a for() loop
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stefan Raab
2015-10-19
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
回答(1 个)
Star Strider
2015-10-19
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 个评论
Star Strider
2015-10-20
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!