Serial summation within a for() loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Stefan Raab
le 19 Oct 2015
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
Réponses (1)
Star Strider
le 19 Oct 2015
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 commentaires
Star Strider
le 20 Oct 2015
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.
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!