Question

In: Advanced Math

The question is to use Matlab to find the clamped cubic spline v(x) that interpolates a...

The question is to use Matlab to find the clamped cubic spline v(x) that interpolates a function f(x) that satisfies: f(0)=0, f(1)=0.5, f(2)=2, f(3)=1.5, f'(0)=0.2, f'(3)=-1 and then plot v(x).

This is my code so far:

x = [0 1 2 3];

y = [0 0.5 2 1.5];

cs = spline(x,[0 y 0]);

xx = linspace(0,3,101);

figure()

plot(x,y,'o',xx,ppval(cs,xx),'-');

IS THIS RIGHT? HOW CAN I GET MATLAB TO GIVE ME THE EQUATION OF v(x)?

Solutions

Expert Solution

MATLAB Code:

close all
clear
clc

x = [0 1 2 3];
y = [0 0.5 2 1.5];
cs = spline(x, [0.2 y -1]); % Slopes at end-points: f'(0) = 0.2 and f'(3) = -1
xx = linspace(0, 3, 101);
figure, plot(x, y, 'o', xx, ppval(cs, xx), '-')
xlabel('x'), ylabel('v(x)')
title('Clamped Spline Interpolation')

% Here cs.coefs is matrix of coefficients of dimensions MxN
% i-th row of cs.coefs contains coefficients of a polynomial of order N for the i-th interval

fprintf('Polynomial [x = 0 to 1]:\n\t')
fprintf('p1(x) = (%.4f)*x^3 + (%.4f)*x^2 + (%.4f)*x + (%.4f)\n', cs.coefs(1,:))
fprintf('Polynomial [x = 1 to 2]:\n\t')
fprintf('p2(x) = (%.4f)*(x - 1)^3 + (%.4f)*(x - 1)^2 + (%.4f)*(x - 1) + (%.4f)\n', cs.coefs(2,:))
fprintf('Polynomial [x = 2 to 3]:\n\t')
fprintf('p3(x) = (%.4f)*(x - 2)^3 + (%.4f)*(x - 2)^2 + (%.4f)*(x - 2) + (%.4f)\n', cs.coefs(3,:))

% Note that for polynomials p2 and p3, the terms (x - 1) and (x - 2) are
% used. It's basically (x - xi), where xi is the starting value of x in the
% corresponding interval.

Output:

Plot:


Related Solutions

Determine by hand calculation (show all steps) the clamped cubic spline that interpolates the data f(-3)...
Determine by hand calculation (show all steps) the clamped cubic spline that interpolates the data f(-3) = 2 ; f(-1) = -3 ; f(0) = 1 ; f(3) = 6 ; f(5) = 3 and satisfies s'(-3) = s'(5) = 0
MATLAB CODE: Making cubic spline iterpolation function. Then, To solve use Tridiagonal matrix algorithm(TDMA) xi -0.5...
MATLAB CODE: Making cubic spline iterpolation function. Then, To solve use Tridiagonal matrix algorithm(TDMA) xi -0.5 -0.4 -0.2 0 0.2 0.4 0.6 0.8 yi 0.04 0.1 0.4 1 0.35 0.2 0.3 0.04
A natural cubic spline S is defined by S(x) = { S0(x) = a0 + b0(x...
A natural cubic spline S is defined by S(x) = { S0(x) = a0 + b0(x − 1) + d0(x − 1)3 , if 1 ≤ x ≤ 2, S1(x) = a1 + b1(x − 2) − 3 4 (x − 2)2 + d1(x − 2)3 , if 2 ≤ x ≤ 3. Use S to interpolate data f(1) = 1, f(2) = 1, f(3) = 0, find a0, b0, d0, a1, b1, and d1.
S(x) is a cubic spline for the function f(x) = sin(pi x/2) + cos(pi x/2) at...
S(x) is a cubic spline for the function f(x) = sin(pi x/2) + cos(pi x/2) at the nodes x0 = 0 , x1 = 1 , x2 = 2 and satisfies the clamped boundary conditions. Determine the coefficient of x3 in S(x) on [0,1] ans. pi/2 -3/2
matlab use matlab to calculate the velocity of the vertical falling ball (v) as a function...
matlab use matlab to calculate the velocity of the vertical falling ball (v) as a function of time by numerical derive the following measurement values.(x is height in meters and y is the landing time in milliseconds) Make sure that the speed in the starting point is 0. Then reset instantaneous velocity as a function of time in a diagram with matlab x=[0.00 0.20 0.40 0.60 0.80 1.00 1.20 1.50 2.00 2.50 3.00 3.40 3.80 4.20 4.60 5.0] y=[[0.00 1.620...
question should be done on Matlab 4) Find the derivative of sin(2x) at x = 0.8...
question should be done on Matlab 4) Find the derivative of sin(2x) at x = 0.8 rad and find the value of h where the error is minimum as compared to the true value i.e. actual value or accurate value. a) Use for loop b) Use element by element operation
Given ? = ???+??? + ??? and ? = ???-3?? + ????. Use MATLAB to find...
Given ? = ???+??? + ??? and ? = ???-3?? + ????. Use MATLAB to find the following: a) ? + ? b) ?  ? c) ? × ? d) A unit vector in the direction of ? − 2? e) ??? f) The component of ? along ? 2. Use MATLAB to convert points ?(11,4,15), ?(10,−14,33) and ?(−33,−14,15) from Cartesian to Cylindrical and Spherical coordinates.
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13...
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13 - 2x2x12 + x12 - x1using initial point (x0, y0) = (1, 2)T to start, and stop when f changes less than 0.0001
Find V(X) of the geometric distribution (Hint for the problem: Use the interchange derivative and summation,...
Find V(X) of the geometric distribution (Hint for the problem: Use the interchange derivative and summation, Find E(X^2), and then use the formula V(X) = E(X^2) - E(X)^2). Please show all work and all steps.
Q1. How many degrees of freedom does a cubic spline with K knots have? Q2. Does...
Q1. How many degrees of freedom does a cubic spline with K knots have? Q2. Does an LDA classifier calculate which direction will maximize the ratio of between class variance over within class variance?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT