matlab spline(),Matlab splinetx

function v = splinetx(x,y,u)

%SPLINETX Textbook spline function.

% v = splinetx(x,y,u) finds the piecewise cubic interpolatory

% spline S(x), with S(x(j)) = y(j), and returns v(k) = S(u(k)).

%

% See SPLINE, PCHIPTX.

% First derivatives

h = diff(x);

delta = diff(y)./h;

d = splineslopes(h,delta);

% Piecewise polynomial coefficients

n = length(x);

c = (3*delta - 2*d(1:n-1) - d(2:n))./h;

b = (d(1:n-1) - 2*delta + d(2:n))./h.^2;

% Find subinterval indices k so that x(k) <= u < x(k+1)

k = ones(size(u));

for j = 2:n-1

k(x(j) <= u) = j;

end

% Evaluate spline

s = u - x(k);

v = y(k) + s.*(d(k) + s.*(c(k) + s.*b(k)));

% -------------------------------------------------------

function d = splineslopes(h,delta)

% SPLINESLOPES Slopes for cubic spline interpolation.

% splineslopes(h,delta) computes d(k) = S'(x(k)).

% Uses not-a-knot end conditions.

% Diagonals of tridiagonal system

n = length(h)+1;

a = zeros(size(h)); b = a; c = a; r = a;

a(1:n-2) = h(2:n-1);

a(n-1) = h(n-2)+h(n-1);

b(1) = h(2);

b(2:n-1) = 2*(h(2:n-1)+h(1:n-2));

b(n) = h(n-2);

c(1) = h(1)+h(2);

c(2:n-1) = h(1:n-2);

% Right-hand side

r(1) = ((h(1)+2*c(1))*h(2)*delta(1)+h(1)^2*delta(2))/c(1);

r(2:n-1) = 3*(h(2:n-1).*delta(1:n-2)+h(1:n-2).*delta(2:n-1));

r(n) = (h(n-1)^2*delta(n-2)+(2*a(n-1)+h(n-1))*h(n-2)*delta(n-1))/a(n-1);

% Solve tridiagonal linear system

d = tridisolve(a,b,c,r);

版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值