matlab三次平滑模型的预测函数
时间: 2024-06-06 07:11:11 浏览: 117
MATLAB_三次指数平滑法_matlab_指数平滑预测_二次指数平滑_
5星 · 资源好评率100%
function y_pred = cubic_smoothing(x, y, lambda, x_pred)
% x: vector of independent variable
% y: vector of dependent variable
% lambda: smoothing parameter
% x_pred: vector of independent variable for prediction
% y_pred: vector of predicted values
n = length(x);
W = zeros(n, n);
for i = 2:n-1
W(i, i-1:i+1) = [1 2 1];
end
W(1,1:2) = [2 1];
W(n,n-1:n) = [1 2];
D = diag(ones(n, 1));
S = D + lambda*W;
S_inv = inv(S);
y_pred = zeros(size(x_pred));
for i = 1:length(x_pred)
K = zeros(n, 1);
for j = 1:n
K(j) = exp(-0.5*(x(j)-x_pred(i))^2);
end
y_pred(i) = K' * S_inv * y / sum(K' * S_inv);
end
end
阅读全文