Variable amount of nested sums

9 Ansichten (letzte 30 Tage)
Elio Xhaferi
Elio Xhaferi am 10 Apr. 2022
Beantwortet: Walter Roberson am 10 Apr. 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

Antworten (1)

Walter Roberson
Walter Roberson am 10 Apr. 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.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by