Hi ALL,
I needed the Taylor series ( about x=0) of cos[2*pi*x] for some application.
I wrote this little simple code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xvalue= -10:.01:10;
Yvalue =zeros(1, length(Xvalue));
for w =1: length(Xvalue)
x0=Xvalue(w);
ss=0;
for mm = 0:100
ss=ss+ (-1)^(mm ) * ((2*pi*x0)^(2*mm)) / factorial(2*mm) ;
end
Yvalue(w)=ss;
end
figure(1)
plot(Xvalue, Yvalue)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I got the below figure, where after x is about =6, the y values started to be NAN.
comments please

 採用された回答

Walter Roberson
Walter Roberson 2019 年 8 月 28 日

0 投票

for mm = 0:100
ss=ss+ (-1)^(mm ) * ((2*pi*x0)^(2*mm)) / factorial(2*mm) ;
What is (2*pi*6)^(2*100) ?
What is factorial(2*100) ?
What is the ratio of those two?

その他の回答 (2 件)

Fawaz Hjouj
Fawaz Hjouj 2019 年 8 月 28 日
編集済み: Fawaz Hjouj 2019 年 8 月 31 日

0 投票

Isnt this series convergent?

3 件のコメント

Walter Roberson
Walter Roberson 2019 年 8 月 28 日
The value might be 0 in the limit, but you are not working in the limit, you are working with floating point numbers with finite precision and you are overflowing that finite precision.
Note the calculating the product of (2*pi*x0)^2 / (2*M) over M=0:100 would not suffer from the same overflow .
Walter Roberson
Walter Roberson 2019 年 8 月 29 日
Who is "Wally"?
Steven Lord
Steven Lord 2019 年 8 月 29 日
According to Wikipedia "Wally or Wallie is a given name, and a nickname for Wallace which ultimately means 'Wales' and Walter."
I don't recognize many of the real people listed on that Wikipedia page; I recognized many more from the Fictional characters section :)

サインインしてコメントする。

Fawaz Hjouj
Fawaz Hjouj 2019 年 8 月 31 日

0 投票

Sorry wrong person

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

質問済み:

2019 年 8 月 28 日

回答済み:

2019 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by