level 1
原程序如下
clear
syms a b;
c=[a b]';
A=[125 135 145 155 215 215 200 160 160 160 140 115 145 125 105 105 115 105 95 95 105 95 185 275 115 95 75 195 135 140 140 130];
B=cumsum(A); % 原始数据的累加
n=length(A);
for i=1:(n-1)
C(i)=(B(i)+B(i+1))/2 %生成累加矩阵
end
>> %计算待定参数的值
D=A;D(1)=[];
D=D';
E=[-C;ones(1,n-1)];
c=inv(E*E')*E*D;
c=c';
a=c(1);b=c(2);
% 预测后续数据
F=[];F(1)=A(1);
for i=2;(n
+3
2)
F(i)=(A(1)-b/a)/exp(a*(i-1))+b/a;
end
ans =
64
>> G=[];G(1)=A(1);
for i=2:(n+10)
G(i)=F(i)-F(i-1); %得出预测出来的数据
end
Attempted to access F(3); index out of bounds because numel(F)=2.
>>
>> end
t1=3-27:4-27;
t2=4-28:5-6;
G;a,b
plot(t1,A,'o',t2,G)
a =
0.0092
b =
163.3686
Error using plot
Vectors must be the same lengths.
>>
2013年05月01日 09点05分