怎么运行matlab,附录一:求GM(1,1)拟合曲线的matlab代码%compute the coefficient(a andu)------------------------n=length(x_orig);%first generate the matrix Bfor i=1:(n-1);B(i)=-(x(i)+x(i+1))/2;endB=[B' ones(n-1,1)];%then generate the matrix
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/08 19:27:30
怎么运行matlab,附录一:求GM(1,1)拟合曲线的matlab代码%compute the coefficient(a andu)------------------------n=length(x_orig);%first generate the matrix Bfor i=1:(n-1);B(i)=-(x(i)+x(i+1))/2;endB=[B' ones(n-1,1)];%then generate the matrix
怎么运行matlab,
附录一:求GM(1,1)拟合曲线的matlab代码
%compute the coefficient(a andu)------------------------
n=length(x_orig);
%first generate the matrix B
for i=1:(n-1);
B(i)=-(x(i)+x(i+1))/2;
end
B=[B' ones(n-1,1)];
%then generate the matrix Y
for i=1:(n-1);
y(i)=x_orig(i+1);
end
Y=y';
%get the coefficient.a=au(1) u=au(2)
au=(inv(B'*B))*(B'*Y);
%--------------------------------------------------------
%change the grey model to symbolicexpression
coef1=au(2)/au(1);
coef2=x_orig(1)-coef1;
coef3=0-au(1);
costr1=num2str(coef1);
costr2=num2str(abs(coef2));
costr3=num2str(coef3);
eq=strcat(costr1,'+',costr2,'e^',costr3,'*(t-1))');
%comparison of calculated and observedvalue
for t=1:n+predict
mcv(t)=coef1+coef2*exp(coef3*(t-1));
end
x_mcv0=diff(mcv);
x_mcve=[x_orig(1) x_mcv0];
x_mcv=diff(mcv(1:end-predict));
x_orig_n=x_orig(2:end);
x_c_error=x_orig_n-x_mcv;
x_error=mean(abs(x_c_error./x_orig_n));
if x_error>0.2
disp('model disqualification!');
elseif x_error>0.1
disp('model check out');
else
disp('model is perfect!');
end
%predicting model and plot gragh
plot(1:n,x_orig,'r*',1:n+predict,x_mcve),'k.';
p=x_mcve(end-predict+1:end);
xlabel('时间序列');
ylabel('仔猪价格');
title('GM(1,1)');
grid on
y=eq;
e=x_error;
p=x_mcve(end-predict+1:end);
怎么运行matlab,附录一:求GM(1,1)拟合曲线的matlab代码%compute the coefficient(a andu)------------------------n=length(x_orig);%first generate the matrix Bfor i=1:(n-1);B(i)=-(x(i)+x(i+1))/2;endB=[B' ones(n-1,1)];%then generate the matrix
猜你是个刚刚接触matlab的,别害怕,一步步的来,你的代码我看了下
Undefined function or variable 'x_orig'.
x_orig 还缺少这个源数据