Answered step by step
Verified Expert Solution
Question
1 Approved Answer
URGENT!!!!!! If you post a copied answer I will DOWN RATE!!!!!!!!! Problem 4: Natural cubic spline in Matlab The goal of this problem is to
URGENT!!!!!! If you post a copied answer I will DOWN RATE!!!!!!!!!
Problem 4: Natural cubic spline in Matlab The goal of this problem is to draw mount Everest with the help of natural cubic splines. We have a rather poor quality photo of the mountain profile, which is given below. You need to set up a coordinate system, and select a set of knots along the edge of the mountain, and find the coordinates for all these interpolating points. We are aware that the mountain profiles are not very clear in that photo, so please use your imagination when you find these approximate points. You may either print out the mountain picture and work on it on a piece of paper, or send the image to some software and locate the coordinates of the interpolating points. Make sure to select at least 20 points. You may use more points if you see fit. After you have generated your data set, you need to find a natural cubic spline inter- polation. Use the functions cspline and cspline_eval, which are available in Section 3.4. Read these two functions carefully, try to understand them before using them. Does it look like there is a smaller peak on the right? Does the peak look rather sharp? How would you deal with this situation, knowing that a single cubic spline function will generate a smoothest" possible interpolation? function z = cspline(t,y) % function z = cspline(t,y) % compute z-coefficients for natural cubic spline % where t is a vector with knots, and y is the interpolating values % z is the output vector n = length(t); z = zeros(n,1); h = zeros(n-1, 1); b = zeros(n-1, 1); u = zeros(n,1); V = zeros(n,1); h = t(2:n)-t(13n-1); b = (y(2:n)-y(13n-1))./h; u(2) = 2* (h(1)+h(2)); (2) = 6*(b(2) -b(1)); for i=3:n-1 % solve the tri-diag system u(i) = 2*(h(i)+h(i-1))-(i-1)^2/u(i-1); v(i) = 6*(b(i)-(i-1))-(i-1)*v(i-1)/(1-1); end for i=n-1:-1:2 z(i) = (v(i)-h(i)*z(i+1))/u(i); end function S = cspline_eval(t,y,z, X_vec) ) % function S = cspline_eval(t,y,z, x_vec) % compute the value of the natural cubic spline at the points x_vec when % t,y,z are given % % Example: t = [0.9, 1.3, 1.9, 2.1]; % y = [1.3, 1.5,1.85, 2.1] % z = cspline(t,y) % x = [0.9: 0.1:2.1] % v = cspline_eval(t,y,z,x) m = length(x_vec); S = zeros(size(x_vec)); n = length(t); for j=1:m x = x_vec(j); for i=n-1:-1:1 if (x-t(i)) >= 0 break end end h = t(i+1)-t(i); s(j) = z(i+1)/(6*h)*(x-t(i))^3-z(i)/(6*h)*(x-t(i+1))^3 ... +(y(i+1)/h-z(i+1)*h/6)*(x-t(i)) - (y(i)/h-z(i)*h/6)*(x-t(i+1)); end +n)*(x- Problem 4: Natural cubic spline in Matlab The goal of this problem is to draw mount Everest with the help of natural cubic splines. We have a rather poor quality photo of the mountain profile, which is given below. You need to set up a coordinate system, and select a set of knots along the edge of the mountain, and find the coordinates for all these interpolating points. We are aware that the mountain profiles are not very clear in that photo, so please use your imagination when you find these approximate points. You may either print out the mountain picture and work on it on a piece of paper, or send the image to some software and locate the coordinates of the interpolating points. Make sure to select at least 20 points. You may use more points if you see fit. After you have generated your data set, you need to find a natural cubic spline inter- polation. Use the functions cspline and cspline_eval, which are available in Section 3.4. Read these two functions carefully, try to understand them before using them. Does it look like there is a smaller peak on the right? Does the peak look rather sharp? How would you deal with this situation, knowing that a single cubic spline function will generate a smoothest" possible interpolation? function z = cspline(t,y) % function z = cspline(t,y) % compute z-coefficients for natural cubic spline % where t is a vector with knots, and y is the interpolating values % z is the output vector n = length(t); z = zeros(n,1); h = zeros(n-1, 1); b = zeros(n-1, 1); u = zeros(n,1); V = zeros(n,1); h = t(2:n)-t(13n-1); b = (y(2:n)-y(13n-1))./h; u(2) = 2* (h(1)+h(2)); (2) = 6*(b(2) -b(1)); for i=3:n-1 % solve the tri-diag system u(i) = 2*(h(i)+h(i-1))-(i-1)^2/u(i-1); v(i) = 6*(b(i)-(i-1))-(i-1)*v(i-1)/(1-1); end for i=n-1:-1:2 z(i) = (v(i)-h(i)*z(i+1))/u(i); end function S = cspline_eval(t,y,z, X_vec) ) % function S = cspline_eval(t,y,z, x_vec) % compute the value of the natural cubic spline at the points x_vec when % t,y,z are given % % Example: t = [0.9, 1.3, 1.9, 2.1]; % y = [1.3, 1.5,1.85, 2.1] % z = cspline(t,y) % x = [0.9: 0.1:2.1] % v = cspline_eval(t,y,z,x) m = length(x_vec); S = zeros(size(x_vec)); n = length(t); for j=1:m x = x_vec(j); for i=n-1:-1:1 if (x-t(i)) >= 0 break end end h = t(i+1)-t(i); s(j) = z(i+1)/(6*h)*(x-t(i))^3-z(i)/(6*h)*(x-t(i+1))^3 ... +(y(i+1)/h-z(i+1)*h/6)*(x-t(i)) - (y(i)/h-z(i)*h/6)*(x-t(i+1)); end +n)*(xStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started