How to code for summation?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ashfaq Ahmed
le 5 Oct 2022
Réponse apportée : Walter Roberson
le 5 Oct 2022
Hi all,
Can anyone please tell me how can I do the coding to complete this sum?

Also, how can I write down the code that adds up one term after one term and plots them? For example,
x = -pi:0,01:pi;
plot(x,term1); hold on;
plot(x,term1+term2); hold on;
plot(x,term1+term2+term3); hold on;
until all 7 terms! Thank you so much fro your help!!
0 commentaires
Réponse acceptée
Walter Roberson
le 5 Oct 2022
Your sin(x) term is constant in n, so you can move it outside the summation.
x = -pi:0.01:pi;
sx = sin(x);
factor = cumsum(2./(1:7))
result = factor .* sx.';
plot(x, result)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Performance and Memory 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!
