java 实现matlab spline_请问matlab的spline函数的具体实现哪儿可以找到呢?

function output = spline(x,y,xx)

dd = ones(yd,1); dx = diff(x); divdif = diff(y,[],2)./dx(dd,:);

if n==2

if isempty(endslopes) % the interpolant is a straight line

pp=mkpp(x,[divdif y(:,1)],sizey);

else % the interpolant is the cubic Hermite polynomial

pp = pwch(x,y,endslopes,dx,divdif); pp.dim = sizey;

end

elseif n==3&&isempty(endslopes) % the interpolant is a parabola

y(:,2:3)=divdif;

y(:,3)=diff(divdif')'/(x(3)-x(1));

y(:,2)=y(:,2)-y(:,3)*dx(1);

pp = mkpp(x([1,3]),y(:,[3 2 1]),sizey);

else % set up the sparse, tridiagonal, linear system b = ?*c for the slopes

b=zeros(yd,n);

b(:,2:n-1)=3*(dx(dd,2:n-1).*divdif(:,1:n-2)+dx(dd,1:n-2).*divdif(:,2:n-1));

if isempty(endslopes)

x31=x(3)-x(1);xn=x(n)-x(n-2);

b(:,1)=((dx(1)+2*x31)*dx(2)*divdif(:,1)+dx(1)^2*divdif(:,2))/x31;

b(:,n)=...

(dx(n-1)^2*divdif(:,n-2)+(2*xn+dx(n-1))*dx(n-2)*divdif(:,n-1))/xn;

else

x31 = 0; xn = 0; b(:,[1 n]) = dx(dd,[2 n-2]).*endslopes;

end

dxt = dx(:);

c = spdiags([ [x31;dxt(1:n-2);0] ...

[dxt(2);2*(dxt(2:n-1)+dxt(1:n-2));dxt(n-2)] ...

[0;dxt(2:n-1);xn] ],[-1 0 1],n,n);

% sparse linear equation solution for the slopes

mmdflag = spparms('autommd');

spparms('autommd',0);

s=b/c;

spparms('autommd',mmdflag);

% construct piecewise cubic Hermite interpolant

% to values and computed slopes

pp = pwch(x,y,s,dx,divdif); pp.dim = sizey;

end

if nargin==2, output = pp; else output = ppval(pp,xx); end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值