冷冻水在哪个设备中:帮我看下matlab程序

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 08:50:40
我对matlab不太懂,我在书上找了段程序测试的时候遇到了一点问题
希望高手帮我看下:
function yhat = splintFE(x,y,xhat,fp1,fpn)
%splintFE Cubic-spline interpolation with fixed slope end conditions
%
%Synopsis: splintFE(x,y,xhat,fp1,fpn)
%
%Input: x,y = vectors of discrete x and y = f(x) values
% xhat = (scalar or vector) x values where interpolant is evaluated
% fp1 = slope at x(1), i,e.,fp1 = f'(x(1))
% fp1 = slope at x(n), i,e.,fp1 = f'(x(n));
%
%output yhat = (vector or scalar) value(s) of the cubic spline interpolant
% evaluated at xhat. size(yhat) = size(xhat)

%--- Set up system of equations for b(1)
x = x(:); y = y(:); xhat = xhat(:); %convert to columu vectors
n = length(x);
dx = diff(x); % vector of x(i+1) - x(i) values
divdif = diff(y)./dx; % vector of divided differences, f[x(i),x(i+1)]

alpha = [0;dx(1:n-2); 0]; % sub diagonal
beta = [1;2*dx(1:n-2)+dx(2:n-1); 1]; % main diagonal
gamma = [0;dx(2:n-2); 0]; % super diagonal
A = tridiags(n,beta,alpha,gamma) % sparse,tridiagonal matrix
delta = [ fp1; ...
3*(divif(2:n-1).*dx(1:n-2) + divif(1:n-2).*dx(2:n-1)); ...
fpn];

% --- Solve the system for b
mmdflag = spparms('autommd'); % store minimum degree ordering flag
spparm('autommd',0); % set that flag to zero
b = A\delta; % solve the system
spparm('autommd',mmdflag); % Reset the minimum degree ordering flag

% --- Compute coefficints of spline interpolants
a = y(1:n-1);
c = (3*divdif - 2*b(1:n-1) - b(2:n))./dx;
d = (b(1:n-1) - 2*divdif + b(2:n))./dx.^2;
b(n) = []; %discard b(n)

% --- Locate each xhat value in the x vector
i = zeros(size(xhat)); % i is index into x such that x(i) <= xhat <= x(i+1)
for m=1:length(xhat) % For vector xhat: x( i(m) ) <= xhat(m) <= x( i(m)+1 )
i(m) = binSearch(x,xhat(m));
end

% --- Nested,vectorized evaluation of the piececewise polynomials
xx = xhat - x(i);
yhat = a(i) + xx.*(b(i) + xx.*(c(i) + xx.*d(i)) );
??? function yhat = splintFE(x,y,xhat,fp1,fpn)
|
Error: Function definitions are not permitted at the prompt or in scripts.
这个是程序运行后出现的结果,好象是没有定义splintFE,请问怎么定义?需要编辑M文件吗?

我也觉得程序每个什么问题,这端程序是 函数splintFE进行有固定斜率端点条件的分段三阶样条插值
我还想问下 MATLAB的工具箱 时怎么导入和添加的????

这段程序没有什么问题,是不是你的给函数splintFE的参数有问题呢?
还有就是你这个函数内部所用的函数 tridiags不存在,如果你要正常使用的话,你就必须要先给出函数 tridiags

另外问一下,你这个函数是做什么的?
我不懂英语所以看不懂注释,只凭感觉猜测是多项式函数的样条插值方面的
哈哈,只是直觉而已,你不要笑我无知.