plotting libnez taylor series
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Youssef Khmou
2013 年 2 月 11 日
write the index form of the series : per example :
N
-
\ n*(n+1)
/ --------
- (n+3)* n
n=0
採用された回答
Youssef Khmou
2013 年 2 月 11 日
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 件のコメント
Youssef Khmou
2013 年 2 月 11 日
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 .
その他の回答 (1 件)
Youssef Khmou
2013 年 2 月 11 日
編集済み: Youssef Khmou
2013 年 2 月 11 日
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 件のコメント
Youssef Khmou
2013 年 2 月 12 日
編集済み: Youssef Khmou
2013 年 2 月 12 日
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)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!