I'm trying to understand the types of numerical errors, to do this I want to calculate $\sin(\pi/2)=1$ numerically. To do this I use the Taylor series of $\sin(x)$ in 0: $$\sin(x)=x-\frac{x^3}{6}+\frac{x^5}{120}-\frac{x^7}{5040}+ \ldots$$
To make the calcultaions I did the following Fortran program:
program main
implicit none
real*8 pi, x, res, error
pi=3.14159265
x = pi/2
res = x - x**3/6 + x**5/120 - x**7/5040
error = 1-res
print*, "Result: ",res
print*, "Error: ", error
end
And I get the following results depending of the degreee of the Taylor series and in the decimals of pi.
If $\pi=3.14$
- Taylor 3rd Degree: 0.92501782114084341
- Taylor 5th Degree: 1.0045086615502121
- Taylor 7th Degree: 0.99984349522599403
- Taylor 9th Degree: 1.0000032059098956
- Taylor 11thDegree: 0.99999962708361323
If $\pi=3.14159265$
- Taylor 3rd Degree: 0.92483221907327295
- Taylor 5th Degree: 1.0045248564076874
- Taylor 7th Degree: 0.99984310136039689
- Taylor 9th Degree: 1.0000035425853664
- Taylor 11thDegree: 0.99999994374102952
And I observe that the error gets bigger if I put more decimals in my $\pi$ approximation. Why is this happening? Edit: Adding more terms to the Taylor expansion (11th degree) makes adding more $\pi$ digits better.
Also, How can I make a better approximation? What method will be better to a problem like this one?
How can I predict the size of these errors?
0.92383592604100528which is worse than with the 3.14 approximation. – Msegade Sep 01 '13 at 10:45