close all;
clc;
%p = [2056 2395 2600 2298 1634 1600 1837 1478 1900 2395 2600 2298 1634 1600 1873 1478 1900 1500 2600 2298 1634 1600 1873 1478 1900 1500 2046];
t = [1873 1478 1900 1500 2046 1556];
p = [ 2056 2395 2600 2298 1634 1600];
%--歸壹化輸入輸出-- 映射到[0,1]--%
pmax = max(p);
pmin = min(p);
P = (p-pmin)./(pmax-pmin);
tmax = max(t);
tmin = min(t);
T = (t-tmin)./(tmax-tmin);
net =newff(P,T,5,{'tansig','purelin'},'traingdx');
%--設置訓練參數--%
net.trainParam.show =50;
net.trainParam.lr = 0.05;
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-3;
net.divideFcn= '';
[net,tr] = train(net,P,T);
A =sim(net,P);
a =A.*(tmax - tmin)+tmin;
x = 7:12;
figure
plot(x,t,'+');
hold on;
plot(x,a,'or');
hold off;
xlabel('month');
ylabel('**')
legend('實際','預測')