QuestionQuestion

Transcribed TextTranscribed Text

1. Write a code to compute a natural spline S(x) which interpolates a collection of given points (o,yo), (=1,yr) (xn,yn) where To < 21 < X2 < < In (do not assume they are equidistributed). Your code should have a triadiagonal solver for the resulting linear system of equations (you're not allowed to use Matlab's \ operator to solve the linear system). 2. One important application of spline interpolation is the construction of smooth curves that are not necessarily the graph of a function but that have a parametric representation I = =(() and y = y(t) for t E [a,b]. Hence one needs to determine two splines interpolating (tz,I;) and (t;,Y;) G = 0,1 n). The are length of the curve is a natural choice for the parameter t. However, this is not known a priori and instead the if's are usually chosen as the distances of consecutive points: to = = (1) Use the values in Table 1 to construct a smooth parametric representation of a curve passing through the points (xj,yj), j = 0, 1, 8 by finding the two natural cubic splines interpolating (t;,If) and 11,45). , = 0, 8, respectively. Tabulate the coefficients of the splines and plot the resulting (parametric) curve. i t; Ij Yj 1.50 0.75 1 0.618 0.90 0.90 2 0.935 0.60 1.00 3 1.255 0.35 0.80 4 1.636 0.20 0.45 5 1.905 0.10 0.20 6 2.317 0.50 0.10 7 2.827 1.00 0.20 8 3.330 1.50 0.25 Table 1: Table of data for Problem 2

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

function [ynew,a,b,c,d] = NatSpline(x,y,xnew)
% ynew = NatSpline(x,y)
% Natural spline interpolation.
% x,y are column n-vectors.
% Assume that n >= 4 and x(1) < ... x(n).
% xnew -- is a set of points in the interval x(1) to x(n) for which
% the natural spline needs to be evaluated.
% On the i-th interval [x(i),x(i+1)] the spline has the form:
% S(z) = a(i) + b(i)(z-x(i)) + c(i)(z-x(i))^2 + d(i)(z-x(i))^2(z-x(i+1).
%
% Outputs:
% ynew -- the values of the natural spline evaluated at the points xnew.
% a,b,c,d,-- the vector of coefficients of the splines
% Usage:   
%   [ynew,a,b,c,d] = NatSpline(x,y,xnew)

      
% First, set up all but the first and last equations that
% define the vector of interior slopes s(2:n-1).

n = length(x);
Dx = diff(x);
yp = diff(y) ./ Dx;
T = zeros(n-2,n-2);
r = zeros(n-2,1);
for i=2:n-3
   T(i,i)   = 2*(Dx(i) + Dx(i+1));
   T(i,i-1) = Dx(i+1);
   T(i,i+1) = Dx(i);
   r(i)    = 3*(Dx(i+1)*yp(i) + Dx(i)*yp(i+1));
end

T(1,1) = 2*Dx(1) + 1.5*Dx(2);
T(1,2) = Dx(1);
r(1) = 1.5*Dx(2)*yp(1) + 3*Dx(1)*yp(2);
T(n-2,n-2) = 1.5*Dx(n-2)+2*Dx(n-1);
T(n-2,n-3) = Dx(n-1);
r(n-2) = 3*Dx(n-1)*yp(n-2) + 1.5*Dx(n-2)*yp(n-1);
%we now need to solve
%stilde = T\r;
A=diag(T);
B=zeros(size(A));
for i=2:n-2
    B(i)=T(i,i-1);
end
C=zeros(size(A));
for i=1:n-3
    C(i)=T(i,i+1);
end

%call the tri diagonal solver: (below)
stilde=tridiag( A, B, C, r );

s1 = (3*yp(1) - stilde(1));
sn = (3*yp(n-1) - stilde(n-2));
s = [s1;stilde;sn];


% Compute the a,b,c,d vector of coefficients for the splines.
   
a = y(1:n-1);
b = s(1:n-1);
c = (yp - s(1:n-1)) ./ Dx;
d = (s(2:n) + s(1:n-1) - 2*yp) ./ (Dx.* Dx);

%next evaluate at the points xnew to obtain the values ynew


for j=1:length(xnew)
    x_val=xnew(j);...
$18.45 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Numerical Analysis Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats