plotting libnez taylor series

1 visualización (últimos 30 días)
AngelsaAtWar
AngelsaAtWar el 11 de Feb. de 2013
hi there i have tried to plot libnez's taylor series as a line graph but it will not show up. correctly it only plots the same reslut value for all terms given. I want to plot 20 terms but am have difficultly doing so. Can anyone help me out?
the function is : pi= 4- 4/3+ 4/5- 4/7....
This is what I have so far thanks to Youssef KHMOU ...
value= input('how many values would you like:');
result=zeros(20,1);
signchange= 1;
result(1)=4;
for k= 1:value
term = signchange * 4/(2*k-1);
result(k+1) =result(k)+ term;
signchange = signchange * (-1) ;
end
plot(result)
the only problem is that I want it to plot somehow from terms 0:20
  2 comentarios
AngelsaAtWar
AngelsaAtWar el 11 de Feb. de 2013
the series is 4-4/3+4/5-4/7.....
Youssef  Khmou
Youssef Khmou el 11 de Feb. de 2013
write the index form of the series : per example :
N
-
\ n*(n+1)
/ --------
- (n+3)* n
n=0

Iniciar sesión para comentar.

Respuesta aceptada

Youssef  Khmou
Youssef Khmou el 11 de Feb. de 2013
esult=0.0 ;
signchange= 1;
for k = 1:1:value
term = signchange * 4/(2*k-1);
result = (result + term)
signchange = signchange * -1 ;
x=1:1: value;
y=result;
plot(x,y,'ok'); hold on end
hold off
  2 comentarios
Youssef  Khmou
Youssef Khmou el 11 de Feb. de 2013
yes, but you have to specify your question, Taylor LEIBNIZ series is general form, you want apply the formula on what function : per example :
sin(x) = Sum (n=0, infinity) (-1)^n * (x^2n+1) / (2n+1)!
, take a look at the answer below .

Iniciar sesión para comentar.

Más respuestas (1)

Youssef  Khmou
Youssef Khmou el 11 de Feb. de 2013
Editada: Youssef Khmou el 11 de Feb. de 2013
AngelsaAtWar :
You have to re-post the question with the function you want use and give a general index forumla :
here is you code with 400 iterations :
value=400;
result=zeros(40,1);
signchange= 1;
result(1)=4;
for k = 1:value-1
term = signchange * 4/(2*k-1);
result(k+1) =result(k)+ term;
signchange = signchange * (-1) ;
end
plot(result)
  2 comentarios
AngelsaAtWar
AngelsaAtWar el 12 de Feb. de 2013
I edited my question above like you asked me to
Youssef  Khmou
Youssef Khmou el 12 de Feb. de 2013
Editada: Youssef Khmou el 12 de Feb. de 2013
ok,
what about the last code, is that what you want ( damped sinusoidal function like) ?
if you only want to plot 20, then give 20 as input to value . Or can you give 100000 , but plot only 20 or truncate other elements starting from 21 to end , you have may options,
plot(result(1:20)) % if you gave more than 20 to values or :
result(21:end)=[], plot(result)

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by