Plotting a power series
Mostrar comentarios más antiguos
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])
Respuestas (1)
KALYAN ACHARJYA
el 24 de Sept. de 2018
Editada: KALYAN ACHARJYA
el 24 de Sept. de 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 comentarios
KALYAN ACHARJYA
el 24 de Sept. de 2018
Editada: KALYAN ACHARJYA
el 24 de Sept. de 2018
t is having only two points 0,300
aa bb
el 24 de Sept. de 2018
KALYAN ACHARJYA
el 24 de Sept. de 2018
the sum of the first 3

aa bb
el 24 de Sept. de 2018
Categorías
Más información sobre Numerical Integration and Differentiation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!