Gray prediction model code

GM (1,1) gray prediction model calculation and check code

function [] = greymodel (Y)
% This program is used to calculate the predicted value of the gray theory model.
Application of mathematical models% is GM (1,1).
% Of the raw data processing method is a cumulative process.
y = input ( 'Enter Data');
n-= length (Y);
YY = ones (n-,. 1);
YY (. 1) = Y (. 1);
for I = 2: n-
YY (I) = YY ( . 1-I) + Y (I);
End
B = ones (1,2-n-);
for I =. 1: (. 1-n-)
B (I,. 1) = - (YY (I) + YY (I + . 1)) / 2;
B (I, 2) =. 1;
End
the BT = B ';
for J =. 1: n--. 1
YN (J) = Y (J +. 1);
End
YN = YN';
A = INV (the BT * B) the BT YN;
A = A (. 1);
U = A (2);
T = U / A;
I =. 1: + n-2;
YYS (I +. 1) = (Y (. 1) -t ..) * exp (-a I) + T;
YYS (. 1) Y = (. 1);
for J = 2 + n-: -12
YS (J) = YYS (J) -yys (-J. 1);
end
x = 1: n;
XS = 2: n + 2;
a = ys (2: n + 2);
plot (x, y, '^ r', XS, is, '
-b');
det = 0;

SUM1 = 0;
sumpe = 0;
for I =. 1: n-
sumpe = sumpe + Y (I);
End
PE = sumpe / n-;
for I =. 1: n-;
SUM1 = SUM1 + (Y (I) -pe) ^. 2;
End
S1 = sqrt (SUM1 / n-);
sumce = 0;
for I = 2: n-
sumce = sumce + (Y (I) -YN (I));
End
CE = sumce / (n--. 1);
SUM2 = 0;
for I = 2: n-;
SUM2 = SUM2 + (Y (I) -YN (I) -CE) ^ 2;.
End
S2 = sqrt (SUM2 / (. 1-n-));
C = (S2) / ( S1);
DISP ([ 'posterior variance ratio:', num2str ©]);
IF C <0.35
DISP ( 'system predicts good precision')
the else IF C <0.5
DISP ( 'system prediction accuracy qualified')
the else IF C <0.65
DISP ( 'system prediction accuracy barely')
the else
DISP ( 'system failure prediction accuracy')
End
End
End

disp ([ 'is fitted next', num2str (YS (n-+. 1))]);
disp ([ 'is then fitted next', num2str (ys (n + 2))]);

Released eight original articles · won praise 0 · Views 123

Guess you like

Origin blog.csdn.net/qq_43620967/article/details/104678500