Plotting Sum of series: whats wrong with this code?

Hello everyone
it ask to plot this eq for k from 0 to 100
does anyone knows thats wrong with this code?
clc
clear
syms k
k = 1:inf;
Requested array exceeds the maximum possible variable size.
F = symsum(((-1)^k+1)/((0.5*k)-0.25),k,1,inf)
plot(k,F)
grid
thanks for your help in advance
regards

 Réponse acceptée

"k from 0 to 100" does not match "k = 1:inf;". In the equation, the sum starts at 1, not as 0. I do not see a reason to solve this symbolically.
k = 1:100;
F = cumsum(((-1).^(k+1)) ./ (0.5*k - 0.25));
plot(k,F)
grid

Plus de réponses (1)

Torsten
Torsten le 21 Déc 2022
Modifié(e) : Torsten le 21 Déc 2022
syms k
K = 1:100;
F = arrayfun(@(K)simplify(symsum((-1)^(k+1)/(0.5*k-0.25),k,1,K)),K)
F = 
figure(1)
hold on
plot(K,double(F),'b')
plot([0 100],[pi pi],'r')
hold off
or the better solution:
k = 1:100;
F = (-1).^(k+1)./(0.5*k-0.25);
sigmaF = cumsum(F);
figure(2)
hold on
plot(k,sigmaF,'b')
plot([0 100],[pi pi],'r')
hold off

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by