Question

Modify this Matlab code for natural spline so it computes clamp Spline compclampspline(x,y,alpha,beta) alpha and beta...

Modify this Matlab code for natural spline so it computes clamp Spline compclampspline(x,y,alpha,beta)

alpha and beta are the derivatives at the ends.

Code for Natural Spline

function [a,b,c,d]=compnatspline(x,y)

function [a,b,c,d]=compnatspline(x,y)

n=length(x);
delx=(x(2:n)-x(1:n-1))';
dely=(y(2:n)-y(1:n-1))';
a=zeros(n,n);
a(1,1)=1; a(n,n)=1;
r(1)=0; r(n)=0;
for row=2:n-1
r(row)=3*(dely(row)/delx(row)-dely(row-1)/delx(row-1));
a(row,row-1)=delx(row-1);
a(row,row)=2*(delx(row-1)+delx(row));
a(row,row+1)=delx(row);
end
c=a\r';
clear a
b(1:n-1)=dely./delx -delx/3.*(2*c(1:n-1)+c(2:n));
d(1:n-1)=(c(2:n)-c(1:n-1))./(3*delx(1:n-1));
a(1:n-1)=y(1:n-1);
c=c(1:n-1);

Homework Answers

Answer #1

The modified Matlab script compClampSpline.m is posted below:

function [a, b, c, d] = compClampSpline(x, y, alpha, beta)

n = length(x);
delx = ( x(2:n)-x(1:n-1) )';
dely = ( y(2:n)-y(1:n-1) )';

a = zeros(n,n);
a(1, 1:2) = [2*delx(1) delx(1)]; r(1) = 3*(dely(1)/delx(1) - alpha);
a(n, n-1:n) = [delx(n-1) 2*delx(n-1)]; r(n) = 3*(beta - dely(n-1)/delx(n-1));

for row = 2:n-1
r(row) = 3*(dely(row)/delx(row)-dely(row-1)/delx(row-1));
a(row, row-1) = delx(row-1);
a(row, row) = 2*(delx(row-1) + delx(row));
a(row, row+1) = delx(row);
end

c = a\r';
clear a

b(1:n-1) = dely./delx -delx/3.*(2*c(1:n-1)+c(2:n));
d(1:n-1) = (c(2:n)-c(1:n-1))./(3*delx(1:n-1));
a(1:n-1) = y(1:n-1);
c = c(1:n-1);

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
MATLAB CODE REQUIRED Consider the problem of estimating y(0.5) for the boundary-value problem y''+ y' =...
MATLAB CODE REQUIRED Consider the problem of estimating y(0.5) for the boundary-value problem y''+ y' = y + 2, y(0) = 0, y'(1) = 2. Find the solution using 2 approaches: (b) Use finite difference with n = 10.Please provide Matlab code. What is y(0.5) value with Matlab? (c) Using bvp4c. Please provide Matlab code. What is y(0.5) value with Matlab?
Let Y ⇠ Gamma(alpha,beta) and conditioned on Y = y, X ⇠ Poisson(y). Find the unconditional...
Let Y ⇠ Gamma(alpha,beta) and conditioned on Y = y, X ⇠ Poisson(y). Find the unconditional distribution of X in the case that alpha = r is an integer and beta=1-p/p
for p in (0, 1). 
Find the conditional distribution of Y|X = x. (Use Bayes’ rule)
USING MATLAB Code for pseudo Random Input N M=0 For i=1 to N X=rand# Y=rand# If...
USING MATLAB Code for pseudo Random Input N M=0 For i=1 to N X=rand# Y=rand# If X^2+ y^2 <= 1, then M=M+1 End the loop Print M/N (This is the probability) Print M/N (this is approximately = Py
Problem 3 you can use Matlab and also i give u the Problem 1 code its...
Problem 3 you can use Matlab and also i give u the Problem 1 code its on Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandpass filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce this is the Problem 1 code and the solutin clear; clc;...
In Matlab: Given the script: x = 1; x = fun(x-1); y = x-1 and the...
In Matlab: Given the script: x = 1; x = fun(x-1); y = x-1 and the function: function y = fun(x) x = x-1; y = x-1; end What is the output a) -2 b) -4 c) -3 d) -1
Using Matlab to solve the problem below Given X=[-2 -1 0 1 2] Y=[1.5 3.2 4.5...
Using Matlab to solve the problem below Given X=[-2 -1 0 1 2] Y=[1.5 3.2 4.5 3.4 2] a). Plot a scatter plot of the data b). Determine the coefficients of the polynomial ?0 + ?1? + ?2?2 which best fits the data c). Plot this function on the same plot as in part ‘a’. USE MATLAB CODE ONLY! USE MATLAB CODE ONLY! THANK YOU
Using for loop and if statement, write a MATLAB code to plot a graph for x(t)...
Using for loop and if statement, write a MATLAB code to plot a graph for x(t) as a function of time t in the range 0 to 12 in increment of 0.01 ?(?) = 1: 0 ≤ ? ≤ 1 2? − 1 1 ≤ ? ≤ 2 3 2 ≤ ? ≤ 3 −2.5? + 10.5 3 ≤ ? ≤ 5 −2 5 ≤ ? ≤ 6 4/3 ? − 10 6 ≤ ? ≤ 9 2 9 ≤...
Problem 1....... you can use Matlab The following Scilab code generates a 10-second “chirp” with discrete...
Problem 1....... you can use Matlab The following Scilab code generates a 10-second “chirp” with discrete frequencies ranging from 0 to 0.2 with a sampling frequency of 8 kHz. clear; Fs = 8000; Nbits = 16; tMax = 10; N = Fs*tMax+1; f = linspace(0.0,0.2,N); x = zeros(f); phi = 0; for n=0:N-1 x(n+1) = 0.8*sin(phi); phi = phi+2*%pi*f(n+1); end sound(x,Fs,Nbits); sleep(10000); //allows full sound to play Add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the...
For each vector field F~ (x, y) = hP(x, y), Q(x, y)i, find a function f(x,...
For each vector field F~ (x, y) = hP(x, y), Q(x, y)i, find a function f(x, y) such that F~ (x, y) = ∇f(x, y) = h ∂f ∂x , ∂f ∂y i by integrating P and Q with respect to the appropriate variables and combining answers. Then use that potential function to directly calculate the given line integral (via the Fundamental Theorem of Line Integrals): a) F~ 1(x, y) = hx 2 , y2 i Z C F~ 1...
Let F ( x , y ) = 〈 e^x + y^2 − 3 , −...
Let F ( x , y ) = 〈 e^x + y^2 − 3 , − e ^(− y) + 2 x y + 4 y 〉. a) Determine if F ( x , y ) is a conservative vector field and, if so, find a potential function for it. b) Calculate ∫ C F ⋅ d r where C is the curve parameterized by r ( t ) = 〈 2 t , 4 t + sin ⁡ π...