Variable amount of nested sums

9 vues (au cours des 30 derniers jours)
Elio Xhaferi
Elio Xhaferi le 10 Avr 2022
So I've been trying to code this equation where F can be any function with k inputs, ,..., are the same for the same subscript and I have m and k as input. I've been struggling to get the nested sums and the way i managed it, is by creating k-many symbolic expressions and iterating over them while summing up k times with symsum, similiar as shown below ( Fk(x) equivalent to F(cos(x) ) where x is our vector with k entries.
The problem is mv(i) take the values 1 to m and I'm not sure how to modify my function so that I can do something like Fk(θ(mv)) because Fk(theta(mv)) doesn't work or similiar stuff.
startsum = Fk(mv)
for i = 1:k
startsum = symsum(startsum, mv(i),1,m)
end
end

Réponses (1)

Walter Roberson
Walter Roberson le 10 Avr 2022
See https://www.mathworks.com/matlabcentral/answers/623358-get-a-combination-of-unique-paths-for-given-pair-of-numbers#comment_1082638 where I show an implementation of what is sometimes called the "odometer" programming pattern.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by