![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528354/image.png)
An efficient way to compute many sums with different number of terms
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Suppose I have 2 functions
and
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528769/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528774/image.png)
Given different values of
, define
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528779/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528784/image.png)
and
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528789/image.png)
For each
, I want to compute the sums
(if
) or
(if
) where
and ϵ are given.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528309/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528529/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528794/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528534/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528799/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528324/image.png)
The number of terms
varies across elements. For example,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528329/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528539/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528544/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528549/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528554/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528559/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528564/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528569/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528574/image.png)
If the number of terms are all the same, i.e.,
, then I think I can vectorize and handle the computation. However, since the length of the sums are not the same, it becomes more difficult for me to handle it efficiently.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/528579/image.png)
Can you help me to compute this in an efficient way?
Thank you very much in advance.
0 commentaires
Réponses (1)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!