Planetary Movement
Prompt
Solution
Analytical
The steps to solve this problem with an analytical solution are fairly straightforward. All we need to do is plug x = pi/2 into the provided equation for f(x). This evaluates to ( pi/2) - 1.5 which is around 0.0708. We use this answer to compare with our numerical approach and to determine how many terms we need on the Taylor series to drop below our maximum allowed error.
Pseudocode for Numerical Approach
%Calculate function values @ 'a' for use in Taylor series y_a0 = (a) - 1 - 0.5*sin(a); %Function at 'a'...y_a7 = 0.5*cos(a); %Seventh Derivative at a % Taylor series approximationsT0 = y_a0; %Zero-th orderT1 = T0 + ((y_a1)*((x_range - a).^1/factorial(1))); ...T7 = T6 + ((y_a7)*((x_range - a).^7/factorial(7)));
%%ErrorError_Numerical_0 = abs(T0 - y_0);...Error_Numerical_7 = abs(T7 - y_0); %Plot f(x) with first, 3rd, 5th, and 7th taylor approximations%Plot Various Errors to show increasing accuracy with higher taylor series%Plot 4th order error
Numerical
Our objective with the numerical approach is to construct a Taylor series expansion of the original function f(x) with base a = pi/2. We then observe the behavior of the Taylor series approximations along the interval ( 0 < x < pi). Adding additional terms to the Taylor series approximation adjusts the new function to more closely fit the original function f(x), thus reducing our error. Our goal is to determine how many additional terms are required on the Taylor series in order to reduce the maximum error along the specified interval to below 0.015. See below for a visual representation of this as well as example calculations and pseudocode (for implementation in MATLAB).
Discussion
Figure 1: Depicts the function with 1st, 3rd, 5th, and 7th order Taylor Approximations
Results
As we increase the amount of terms we add to the taylor series the approximations become significantly more accurate. Notice in figure 1 how the 7th-order approximation hugs the function on the given interval, almost exactly estimating its change. As we will see in the error analysis, a fourth-order taylor approximation is sufficient to minimze error along the given interval of x below 0.015.
Error Analysis
Figure 2: Depicts the error for the fourth-order Taylor approx.
Notice how the error spikes on both ends of the interval, and is minimal at around x = 1.57, which is our base point "a = pi/2". The maximum error for the fourth-order approximation on this interval is 0.010, which is below our target of 0.015. The third-order error does not meet this criterion.
Figure 3: Various errors for higher-order Taylor approx.
Notice how the 2nd order has a signifcantly larger error compared to the 6th order, which practically hugs the y-intercept. This is because adding more terms causes a Taylor approximation to "behave" more like the original function.