Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please explain using matlab codes thank you very much The aim of this lab is to write a function to compute the coefficients for a
Please explain using matlab codes thank you very much
The aim of this lab is to write a function to compute the coefficients for a cubic spline interpolating function and then to use the coefficients to compute a cubic spline interpolating polynomial. We will focus on natural splines. The algorithm for the coefficients of a cubic spline interpolating polynomial is (Algorithm 3.4 in the text). The algorithm for solving the tridiagonal system is Algorithm 3.7 in the text. INPUT X = (XO.....), Y = (f(x)...,f(x)) =(,...,4.), OUTPUT 4,b,c,,d, for j=0...n-1 the coefficients, where the cubic spline is: S(x)= S/(x) = 4, +b,(x - x))+c,(x - x)* +d;(x - x))", for x sxs xj STEP 1. For i=0,1,...n-1 h - X.-X End For STEP 2. 3 For i=1,...n-1 a. ----(9,-a)-(-) h End For STEP 3. Set %STEPS 3, 4, 5 and part of 6 solve the tridiagonal linear system. 6-1 M - 0 2 - 0 STEP 4. For i=1,...n-1 1, -2(X.-X)-4-1 4-11 3, -a, -h...) End For STEP 5. Set 1-1 5-0 =0 STEP 6. For j-n-1, 1-2,...,0 9= 3; -40 b) = (0,2-a)/h -h (94+20)/3 d) -(4-6)/(3h) End For STEP 7. OUTPUT ,b,c,d, for j = 0,.,1-1 STOP 1. Compute and graph the natural cubic spline interpolant for the data shown in the table below. To plot, use these points, together with the uniformly spaced points given in problem 3 below. x -2.4061 -1.0830 -0.6440 -0.4068 -0.2448 -0.1158 0 0.1158 0.2448 0.4068 0.6440 1.0830 2.4061 f(x) -0.3984 -0.7611 -0.9688 -0.9791 -0.7899 -0.4397 0 0.4397 0.7899 0.9791 0.9688 0.7611 0.3984 2. Use your Lagrange interpolation algorithm from computer assignment 1 to compute the corresponding Lagrange polynomial interpolant, at the same points as listed in part 3. How does the result compare to that for the cubic spline? Explain your results. 3. The function given the table above is: f()= Use the cubic spline 1/4+r? interpolant you found above to approximate the function at the uniformly spaced grid points z=linspace(-2,2,10). What is the maximum error for the cubic spline interpolant? How does the result compare to that predicted by the theoretical error estimate? The aim of this lab is to write a function to compute the coefficients for a cubic spline interpolating function and then to use the coefficients to compute a cubic spline interpolating polynomial. We will focus on natural splines. The algorithm for the coefficients of a cubic spline interpolating polynomial is (Algorithm 3.4 in the text). The algorithm for solving the tridiagonal system is Algorithm 3.7 in the text. INPUT X = (XO.....), Y = (f(x)...,f(x)) =(,...,4.), OUTPUT 4,b,c,,d, for j=0...n-1 the coefficients, where the cubic spline is: S(x)= S/(x) = 4, +b,(x - x))+c,(x - x)* +d;(x - x))", for x sxs xj STEP 1. For i=0,1,...n-1 h - X.-X End For STEP 2. 3 For i=1,...n-1 a. ----(9,-a)-(-) h End For STEP 3. Set %STEPS 3, 4, 5 and part of 6 solve the tridiagonal linear system. 6-1 M - 0 2 - 0 STEP 4. For i=1,...n-1 1, -2(X.-X)-4-1 4-11 3, -a, -h...) End For STEP 5. Set 1-1 5-0 =0 STEP 6. For j-n-1, 1-2,...,0 9= 3; -40 b) = (0,2-a)/h -h (94+20)/3 d) -(4-6)/(3h) End For STEP 7. OUTPUT ,b,c,d, for j = 0,.,1-1 STOP 1. Compute and graph the natural cubic spline interpolant for the data shown in the table below. To plot, use these points, together with the uniformly spaced points given in problem 3 below. x -2.4061 -1.0830 -0.6440 -0.4068 -0.2448 -0.1158 0 0.1158 0.2448 0.4068 0.6440 1.0830 2.4061 f(x) -0.3984 -0.7611 -0.9688 -0.9791 -0.7899 -0.4397 0 0.4397 0.7899 0.9791 0.9688 0.7611 0.3984 2. Use your Lagrange interpolation algorithm from computer assignment 1 to compute the corresponding Lagrange polynomial interpolant, at the same points as listed in part 3. How does the result compare to that for the cubic spline? Explain your results. 3. The function given the table above is: f()= Use the cubic spline 1/4+r? interpolant you found above to approximate the function at the uniformly spaced grid points z=linspace(-2,2,10). What is the maximum error for the cubic spline interpolant? How does the result compare to that predicted by the theoretical error estimateStep 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