Question about Taylor series
Show older comments
I am trying to write a code that output a scalor apporximation for function "sin(x)" that have an error less than 0,05. I try to write Taylor series myself(I cannot use "taylor" code) but my error keep getting larger and larger( the wrror supposed to be smaller and smaller). My math is really bad and I don't know why I keep getting wrong answer. Can anyone help me figure out what's wrong for my code and how can I fix it?
Thanks
Answers (1)
Torsten
on 2 Apr 2019
0 votes
d(1) = cos(a), d(2) = -sin(a), d(3) = -cos(a), d(4) = sin(a)
So your if-statement to determine f^(n)(a) is wrong.
Further, "error" must be defined as
error = abs((y(end)-k)/k)
Further, you should not always explicitly calculate (x-a)^n/n!. Note that
(x-a)^(n+1)/(n+1)! = (x-a)^n/n! * (x-a)/(n+1).
So you can use a recursion to determine (x-a)^(n+1)/(n+1)! from (x-a)^n/n!.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!