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...
Write a MATLAB m file to plot the 3-D curve represented by a multivariable function z(x,y)...
Write a MATLAB m file to plot the 3-D curve represented by a multivariable function z(x,y) = x2 −0.5y2 over x ∈ [−2,2] and y ∈ [−2,2]. Use a 2 point thickness. For both x an y axes, choose the grid size to be 0.05. Clearly label and title your plot. Rotate the view at an azymuth of −20 , and elevation of 20 . You need to use the following commands: x=-2:0.05:2; y=x; z=x.^2-0.5*y.^2; plot3(x,y,z,’LineWidth’,2) label(’ My 3D curve’);...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have provided three questions. Make sure to answer them. (b) Now on the MATLAB prompt, let us create any two 3 × 3 matrices and you can do the following: X=magic(3); Y=magic(3); X*Y matrixMultiplication3by3(X,Y) (c) Now write a new function in MATLAB called matrixMultiplication that can multiply any two n × n matrix. You can safely assume that we will not test your program with...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a...
    asked 16 seconds ago
  • Suppose the number of cars in a household has a binomial distribution with parameters n =...
    asked 3 minutes ago
  • HR needs some information on the new interns put into a database. Given an id, email,...
    asked 24 minutes ago
  • Problem solving strategies Questions years = input("Enter a number of years and I'll tell you how...
    asked 28 minutes ago
  • Calculate ?Hrxn for the following reaction: CH4(g)+4Cl2(g)?CCl4(g)+4HCl(g) Use the following reactions and given ?H?s. C(s)+2H2(g)?CH4(g)?H=?74.6kJC(s)+2Cl2(g)?CCl4(g)?H=?95.7kJH2(g)+Cl2(g)?2HCl(g)?H=?184.6kJ Express...
    asked 35 minutes ago
  • ASCII (American Standard Code for Information Interchange) has an encoding for every character of the alphabet,...
    asked 49 minutes ago
  • Is home confinement with electronic monitoring a deterrent? Are there negatives to being confined to one’s...
    asked 1 hour ago
  • Social hostility can have severe lasting effects of interperpersonal relationship during our adolescence years, which if...
    asked 1 hour ago
  • - A series RLC circuit has R=15 ?, L=1.5 H, and C=15 ?F. (a) For what...
    asked 1 hour ago
  • TV Circuit has 30 large-screen televisions in a warehouse in Erie and 60 large-screen televisions in...
    asked 1 hour ago
  • Charges q1, q2, q3, and q4 are placed in sequential order at the corners of a...
    asked 1 hour ago
  • Let X~GEOM(0.7). Let Y=e^2x. Find E[Y].
    asked 1 hour ago