Problem 1: A car traveling along a straight road is clocked at a number of point
ID: 3904704 • Letter: P
Question
Problem 1: A car traveling along a straight road is clocked at a number of points. The data from the observations are given in the following table, where the time is in seconds, the distance is in feet, and the speed is in feet per second. Time 0 3 5 8 13 Distance 225 383 623 993 Speed 75 77 0 74 72 Write a program which uses Newton's divided difference to compute the Hermite Output the divided difference table. What is the predicted position at polynomial to predict the position of the car att 10s. t 10s?
Explanation / Answer
package org.apache.commons.math3.analysis.interpolation; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableVectorFunction; import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.NoDataException; import org.apache.commons.math3.exception.ZeroException; import org.apache.commons.math3.exception.util.LocalizedFormats; import org.apache.commons.math3.util.CombinatoricsUtils; /** Polynomial interpolator using both sample values and sample derivatives. ** The interpolation polynomials match all sample points, including both values * and provided derivatives. There is one polynomial for each component of * the values vector. All polynomials have the same degree. The degree of the * polynomials depends on the number of points and number of derivatives at each * point. For example the interpolation polynomials for n sample points without * any derivatives all have degree n-1. The interpolation polynomials for n * sample points with the two extreme points having value and first derivative * and the remaining points having value only all have degree n+1. The * interpolation polynomial for n sample points with value, first and second * derivative for all points all have degree 3n-1. *
* */ public class HermiteInterpolator implements UnivariateDifferentiableVectorFunction { /** Sample abscissae. */ private final List abscissae; /** Top diagonal of the divided differences array. */ private final List topDiagonal; /** Bottom diagonal of the divided differences array. */ private final List bottomDiagonal; /** Create an empty interpolator. */ public HermiteInterpolator() { this.abscissae = new ArrayList(); this.topDiagonal = new ArrayList(); this.bottomDiagonal = new ArrayList(); } /** Add a sample point. ** This method must be called once for each sample point. It is allowed to * mix some calls with values only with calls with values and first * derivatives. *
** The point abscissae for all calls must be different. *
* @param x abscissa of the sample point * @param value value and derivatives of the sample point * (if only one row is passed, it is the value, if two rows are * passed the first one is the value and the second the derivative * and so on) * @exception ZeroException if the abscissa difference between added point * and a previous point is zero (i.e. the two points are at same abscissa) * @exception MathArithmeticException if the number of derivatives is larger * than 20, which prevents computation of a factorial */ public void addSamplePoint(final double x, final double[] ... value) throws ZeroException, MathArithmeticException { for (int i = 0; i 1) { double inv = 1.0 / CombinatoricsUtils.factorial(i); for (int j = 0; j