taylor series expansion of cosx
Ältere Kommentare anzeigen
Hi everyone,
I'm struggling with a question below:
Write a script file that computes cos(x) for the given x using the first 20 terms of the power series. Use an array to store the successive terms but do not use the symbolic toolkit, or the factorial function built into Matlab.The code should not calculate each term from scratch but use the previous one to find the next.
1 Kommentar
Geoff Hayes
am 18 Nov. 2014
Jiang - what have you tried so far? The Taylor Series definition can be found here and is straightforward. What exactly is preventing you from implementing your function?
Antworten (1)
Roger Stafford
am 18 Nov. 2014
Bearbeitet: Roger Stafford
am 18 Nov. 2014
0 Stimmen
Hint to Jiang: Note that in the successive terms of the series for cos(x), there is a rather simple arithmetic operation that can be done to each term to obtain the next term in the series. For example, what would you have to do to (+x^4/4!) to get (-x^6/6!)? That is what your assignment is asking you to do. That is also how you can avoid calling on the factorial function.
2 Kommentare
John D'Errico
am 18 Nov. 2014
A nice trick that I used when I wrote HPF, if you will go out to the x^n term, is to factor out factorial(n)/x^n from the entire series. Then work backwards, starting with the last term in the series. This lets you sum the small terms first. It allows you to avoid almost all of the divides, but one at the very end.
Roger Stafford
am 18 Nov. 2014
I agree with you, John. For many such series if one knows how many terms are to be used, it is more accurate to work backwards in the series so that the terms become successively larger rather than smaller. However, I have the feeling that the instructor who devised this question did not expect this degree of sophistication from their students.
Kategorien
Mehr zu Expansion finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!