📄 demo_spline.m
字号:
%% Cubic Spline Interpolation%clear;%% interpolation of Runge's function (1+x^2)^(-1)% on the interval [-5, 5]%clear;% Interval on which Runge's function is to be approximatedA = -5;B = 5;% evaluate Runge's function at zm = 1000;h = (B-A)/(m-1);z = (A:h:B);r = 1 ./(1+z.^2);plot(z, r, 'k'); hold on % plot Runge's functionn = input(' number of interpolation points n = ')% compute equidistant interpolation points% and function values to be interpolated h = (B-A)/(n-1); x = (A:h:B); f = 1 ./ (1+x.^2); fpa = -2*A/(1+A^2)^2; % derivative of Runge's function at -5 fpb = -2*B/(1+B^2)^2; % derivative of Runge's function at +5 % Compute free cubic spline[a, b, c, d, iflag] = cfspline( x, f );s = csplineeval( x, a, b, c, d, z );plot(z, s, 'r:'); hold on % plot free cubic spline% Compute clamped cubic spline[a, b, c, d, iflag] = ccspline( x, f, fpa, fpb );s = csplineeval( x, a, b, c, d, z );plot(z, s, 'g--'); hold off % plot clamped cubic splinelegend('Runge''s fctn.', 'free cubic spline', 'clamped cubic spline')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -