An approximation of sinx around the point x 0 can be repres

An approximation of sin(x) around the point x = 0 can be represent as a Taylor series as follow,

Write a C code does the following

b. Since the expansion is made around x=0, it will start to miss-predict the value once x is far from 0. Make a table in the following form to find out where the Taylor series (of seventh order) fail to predict the sin(x) within an error of 1%

x

true value

3rd order value

3rd order error

5rd order value

5rd order error

7rd order value

7rd order error

0.01

0.02

0.03

Note: use function “sin()” within “math.h” as the accurate result.

x

true value

3rd order value

3rd order error

5rd order value

5rd order error

7rd order value

7rd order error

0.01

0.02

0.03

\"image006.png\"

Solution

C Code: #include #include long int factorial(int m) { if (m==0 || m==1) return (1); else return (m*factorial(m-1)); } double power(double x,int n) { double val=1; int i; for (i=1;i<=n;i++) { val*=x; } return val; } double sine(double x) { int n; double val=0; for (n=0;n<8;n++) { double p = power(-1,n); double px = power(x,2*n+1); long fac = factorial(2*n+1); val += p * px / fac; } return val; } int main() { double x; printf(\"Enter angles in degrees: \"); scanf(\"%lf\",&x); printf(\"\ Value of sine of %.2f is %.2lf\ \",x,sine(x * M_PI / 180)); printf(\"\ Value of sine of %.2f from library function is %.2lf\ \",x,sin(x * M_PI / 180)); return 0; } Error order values x True Value 3rd order value 3rd order error Error percentage 5th order value 5th order error Error percentage 7th orde value 7th order error Error percentage 0.01 0.009999833 0.009999833 8.3333E-13 8.3335E-09 0.009999833 0 0 0.009999833 0 0 0.02 0.019998667 0.019998667 2.6666E-11 1.3334E-07 0.019998667 -2.5327E-16 -1.2664E-12 0.019998667 0 0 0.03 0.0299955 0.0299955 2.025E-10 6.7509E-07 0.0299955 -4.3368E-15 -1.4458E-11 0.0299955 0 0 0.04 0.039989334 0.039989333 8.533E-10 2.1338E-06 0.039989334 -3.2509E-14 -8.1293E-11 0.039989334 0 0 0.05 0.049979169 0.049979167 2.604E-09 5.2102E-06 0.049979169 -1.5501E-13 -3.1015E-10 0.049979169 0 0 0.06 0.059964006 0.059964 6.4794E-09 1.0806E-05 0.059964006 -5.554E-13 -9.2623E-10 0.059964006 0 0 0.07 0.069942847 0.069942833 1.4004E-08 2.0022E-05 0.069942847 -1.6339E-12 -2.3361E-09 0.069942847 1.11022E-16 1.58733E-13 0.08 0.079914694 0.079914667 2.7303E-08 3.4165E-05 0.079914694 -4.1606E-12 -5.2063E-09 0.079914694 3.88578E-16 4.86241E-13 0.09 0.089878549 0.0898785 4.9198E-08 5.4738E-05 0.089878549 -9.489E-12 -1.0558E-08 0.089878549 1.05471E-15 1.17349E-12 0.1 0.099833417 0.099833333 8.3313E-08 8.3453E-05 0.099833417 -1.9839E-11 -1.9872E-08 0.099833417 2.7478E-15 2.75239E-12 0.11 0.109778301 0.109778167 1.3417E-07 0.00012222 0.109778301 -3.8659E-11 -3.5215E-08 0.109778301 6.4948E-15 5.91629E-12 0.12 0.119712207 0.119712 2.0729E-07 0.00017316 0.119712207 -7.1081E-11 -5.9376E-08 0.119712207 1.42109E-14 1.18708E-11 0.13 0.129634143 0.129633833 3.0929E-07 0.00023858 0.129634143 -1.2447E-10 -9.6018E-08 0.129634143 2.91989E-14 2.25241E-11 0.14 0.139543115 0.139542667 4.4798E-07 0.00032103 0.139543115 -2.091E-10 -1.4984E-07 0.139543115 5.69267E-14 4.07951E-11 0.15 0.149438132 0.1494375 6.3247E-07 0.00042323 0.149438133 -3.389E-10 -2.2678E-07 0.149438132 1.05888E-13 7.08571E-11 0.16 0.159318207 0.159317333 8.7328E-07 0.00054814 0.159318207 -5.3242E-10 -3.3419E-07 0.159318207 1.89349E-13 1.18849E-10 0.17 0.169182349 0.169181167 1.1824E-06 0.00069889 0.16918235 -8.1384E-10 -4.8104E-07 0.169182349 3.26711E-13 1.93112E-10 0.18 0.179029573 0.179028 1.5734E-06 0.00087886 0.179029575 -1.2142E-09 -6.782E-07 0.179029573 5.4648E-13 3.05245E-10 0.19 0.188858895 0.188856833 2.0616E-06 0.00109163 0.188858897 -1.7727E-09 -9.3862E-07 0.188858895 8.88928E-13 4.70684E-10 0.2 0.198669331 0.198666667 2.6641E-06 0.00134099 0.198669333 -2.5383E-09 -1.2776E-06 0.198669331 1.4104E-12 7.09923E-10 0.8 0.717356091 0.714666667 0.00268942 0.37490784 0.717397333 -4.1242E-05 -0.00574923 0.717355723 3.67725E-07 5.12611E-05 1.00991 0.846783974 0.838239067 0.00854491 1.00910113 0.846993583 -0.00020961 -0.02475352 0.84678099 2.98375E-06 0.000352362
An approximation of sin(x) around the point x = 0 can be represent as a Taylor series as follow, Write a C code does the following b. Since the expansion is mad
An approximation of sin(x) around the point x = 0 can be represent as a Taylor series as follow, Write a C code does the following b. Since the expansion is mad

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site