Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Mathematica problems Piecewise Cubic Interpolation without specifying derivatives In this part, you will improve upon the previous part in the following way. The aim is

Mathematica problems

Piecewise Cubic Interpolation without specifying derivatives

In this part, you will improve upon the previous part in the following way. The aim is to construct a continuous piecewise cubic function which is differentiable and interpolates a list of data points where each data point has the form (xi,yi). That is, the list of data will *not* include the derivates that must be interpolated as well; instead you must use the given data to provide reasonable values for those derivatives and then construct the piecewise cubic interpolating function using you work in the previous part. There are two main methods to do this: a naive method and a more sophisticated method. We describe each below. Naive method: The issue is that for each pair (xi,yi) we must assign a number ypi which will be the slope at that point. If (xi,yi) is not an end point, then there is a point before it (call it (xj,yj)) and a point after it (call it (xk,yk)), and then one can define ypi=(yk-yj)/(xk-xj). The slopes at end points can be determined by ypi=(yk-yi)/(xk-xi) or ypi=(yi-yj)/(xi-xj) as appropriate.

Sophisticated method: This method will likely involve more linear algebra to implement, but it is far more standard, and it generally yields a better result because the piecewise cubic function is not just continuous and differentiable, but it is twice differentiable! That is, the second derivative of the interpolating function is continuous (in fact, the second derivative is continuous and piecewise linear). This is achieved in the following manner. Suppose we are given n+1 data points to interpolate through. Then there are n intervals on which to define a cubic polynomial. Each such cubic polynomial gives rise to 4 unknowns. And because each interval has two end points specified (like (x1,y1) and (x2,y2) which will be given) it will generate 2 equations. Thus for each segment, we have 2 equations and 4 unknowns. Taking all the segments together, we then have 2n equations with 4n unknowns. However, because we want the resulting function to be differentiable, we will require that the appropriate derivates match up between segments. That is, we will want the derivative at the right end point of interval i to equal the derivative at the left end point of interval i+1. This yields n-1 more equations. And we can ask the second derivatives to match up as well. This yields another n-1 equations. All together, this yields 4n unknowns and 4n-2 equations. An ad hoc (but fairly standard) additional requirement is for the second derivative of the resulting function to be zero at the outermost end points. This requirement then yields two more equations, for a grand total of 4n equations and 4n unknowns. By solving this linear system, one obtains parameters so that the the resulting function is continuously twice differentiable and interpolates through the given list of data points. Such a result is often called a cubic spline.

Choose one of the above methods to implement on the following data set. Plot your result.

myData = Table[{x, Cos[x]}, {x, 0, 2*N[Pi], 2*N[Pi]/6}]

given code

myCubicInterpolator[x_, myData_] := Module[{x1, y1, yp1, x2, y2, yp2, a, b, c, d}, x1 = myData[[1]][[1]]; y1 = myData[[1]][[2]]; yp1 = myData[[1]][[3]]; x2 = myData[[2]][[1]]; y2 = myData[[2]][[2]]; yp2 = myData[[2]][[3]]; a = -((2 y1 - 2 y2 - x1 yp1 + x2 yp1 - x1 yp2 + x2 yp2)/(x1 - x2)^3); b = -((-3 x1 y1 - 3 x2 y1 + 3 x1 y2 + 3 x2 y2 + x1^2 yp1 + x1 x2 yp1 - 2 x2^2 yp1 + 2 x1^2 yp2 - x1 x2 yp2 - x2^2 yp2)/(x1 - x2)^3); c = -((6 x1 x2 y1 - 6 x1 x2 y2 - 2 x1^2 x2 yp1 + x1 x2^2 yp1 + x2^3 yp1 - x1^3 yp2 - x1^2 x2 yp2 + 2 x1 x2^2 yp2)/(x1 - x2)^3); d = -((-3 x1 x2^2 y1 + x2^3 y1 - x1^3 y2 + 3 x1^2 x2 y2 + x1^2 x2^2 yp1 - x1 x2^3 yp1 + x1^3 x2 yp2 - x1^2 x2^2 yp2)/(x1 - x2)^3); a*x^3 + b*x^2 + c*x + d ]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The 3 Signal The Investing Technique That Will Change Your Life

Authors: Jason Kelly

1st Edition

0142180955, 978-0142180952

More Books

Students also viewed these Finance questions

Question

What are the advantages and disadvantages of leasing ?

Answered: 1 week ago

Question

Name is needed for identifying organisms ?

Answered: 1 week ago

Question

4. Label problematic uses of language and their remedies

Answered: 1 week ago