Plotting a power series
Afficher commentaires plus anciens
I want to plot a power series with the first non zero term, sum of the first two terms, up to a sum of terms defined by the for loop. I am confused how to add each sum because when I try g(n+1)=g(n)+ series it tells me the number of elements in A and B must be the same. The original function is: 10*cos(50t). I have found the series as seen inside the for loop but it does not plot the summations
clear;
N=400;
prompt = ('Enter number of terms to sum: ');
i=input(prompt);
t=linspace(0,300,N+1);
f=10*cos(50*t);
g=zeros(1,N+1);
for n=1:i
g = g + ((-1)^n * (2500^n) * t.^(2*n)/(2*factorial(n)))
end
hold on
plot(t,g)
axis([0 150 -12 15])
Réponses (1)
KALYAN ACHARJYA
le 24 Sep 2018
Modifié(e) : KALYAN ACHARJYA
le 24 Sep 2018
% I didn't find any error during running the code, May be there is logical error
clc;
clear;
close all;
N=400;
prompt=('Enter number of terms to sum:');
i=input(prompt);
t=linspace(0,300,N+1);
f=10*cos(50*t);
g=zeros(1,N+1);
for n=1:i
g = g + ((-1)^n * (2500^n) * t.^(2*n)/(2*factorial(n)));
end
hold on
plot(t,g)
axis([0 150 -12 15])

4 commentaires
KALYAN ACHARJYA
le 24 Sep 2018
Modifié(e) : KALYAN ACHARJYA
le 24 Sep 2018
t is having only two points 0,300
aa bb
le 24 Sep 2018
KALYAN ACHARJYA
le 24 Sep 2018
the sum of the first 3

aa bb
le 24 Sep 2018
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!