X linspace 1121 fx exp x220 abcd ncsplinexfx y

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a = f(1:n-1); c = y(1:n-1); 13. (Ex.) Add one line each to obtain the coefficients “b” and “d”. Refer to the Background section for the formulas. 14. Finally, add the line “return” at the end and save the file. 15. Test the function by using the following lines which can be downloaded from IVLE (“lab2 task2.m”). You should see that the maximum error is quite small even though we haven’t optimized the choice of the nodes. x = linspace(-1,1,21); fx = exp(-(x.^2)*20); [a,b,c,d] = ncspline(x,fx); y = linspace(-1,1,2e5); fy = exp(-(y.^2)*20); P = spline(x,fx); P.coefs = [d c b a]; Py = ppval(P,y); format long E = max(abs(fy-Py)) plot(y, fy, ’b-’, y, Py, ’r-’, x, fx, ’g.’); Remark: The line “P = spline(x,fx);” uses a Matlab built-in function that com′′′ putes the coefficients of the cubic spline (under the boundary conditions S0 (x0 ) = ′′ ′′′ ′′′ S1 (x0 ) and S...
View Full Document

This document was uploaded on 10/10/2013.

Ask a homework question - tutors are online