How can I change the variable x0 to x2,x3,x4,...xn . So it still produces the same pattern?

조회 수: 3 (최근 30일)
.
  댓글 수: 2
Stephen23
Stephen23 2022년 8월 18일
편집: Stephen23 2022년 8월 18일
Original question from Azhahra Vindy Ariesta retrieved from Google Cache:
How can I change the variable x0 to x2,x3,x4,...xn . So it still produces the same pattern?
Hi guys, your help will mean a lot.
So I'm making prediction modeling with Gray GM(1,N) method. In the formula it is necessary to define the values of the variables X and Y. Where in my program, the variable Y is A and the variable X is x0. The X variable that I have there are 7 factors that affect the Y variable.
But what my program is asking for, each X variable should be separated. So in this case, I'm confused about changing the loop function and changing what it should have been
x0 = [408, 454, 941, 17162, 35687, 19932, 61510, 81608, 122599, 199153, 156101, 120015;
124171, 190032, 219189, 152435, 130347, 191144, 133795, 53560, 31457, 26162, 15893, 20052;
70409, 207282, 1494766, 1433620, 1110495, 2224241, 2359721, 2913705, 2800503, 912552, 600338, 297624;
204975, 190683, 122735, 60850, 46974, 33007, 65187, 79223, 53214, 48594, 26030, 29108;
67018, 38201, 19335, 11657, 12855, 6542, 6611, 4101, 2953, 2723, 1313, 1393;
190988, 182134, 120311, 60621, 44094, 31392, 53312, 71792, 50007, 44888, 24092, 27284;
72365, 46900, 21759, 11886, 15735, 8157, 18336, 11826, 6160, 5761, 3251, 3537];
then changed to:
x0 = [408, 454, 941, 17162, 35687, 19932, 61510, 81608, 122599, 199153, 156101, 120015];
x1 = [124171, 190032, 219189, 152435, 130347, 191144, 133795, 53560, 31457, 26162, 15893, 20052];
x2 = [ 70409, 207282, 1494766, 1433620, 1110495, 2224241, 2359721, 2913705, 2800503, 912552, 600338, 297624];
etc. to xn.
This is my current program
clear
clc
A =[85983, 70017, 42320, 26565, 21439, 113409, 271185, 35930, 7182, 3775, 2407, 1350]; %(X0(1))
x0 =[408, 454, 941, 17162, 35687, 19932, 61510, 81608, 122599, 199153, 156101, 120015; %(X0(2))
124171, 190032, 219189, 152435, 130347, 191144, 133795, 53560, 31457, 26162, 15893, 20052; %(X0(3))
70409, 207282, 1494766, 1433620, 1110495, 2224241, 2359721, 2913705, 2800503, 912552, 600338, 297624; %(X0(4))
204975, 190683, 122735, 60850, 46974, 33007, 65187, 79223, 53214, 48594, 26030, 29108; %(X0(5))
67018, 38201, 19335, 11657, 12855, 6542, 6611, 4101, 2953, 2723, 1313, 1393; %(X0(6))
190988, 182134, 120311, 60621, 44094, 31392, 53312, 71792, 50007, 44888, 24092, 27284; %((X0(7))
72365, 46900, 21759, 11886, 15735, 8157, 18336, 11826, 6160, 5761, 3251, 3537]; %(X0(8))
[n,m]=size(x0); % Constitutes a matrix
AGO=cumsum(A);
T=1;
x1=zeros(n,m+T);
for i=1:n
for j=1:m
for k=1:j
x1(i,j)=x1(i,j)+x0(i,k);% The original data is accumulated once to get xi(1)
end
end
end
for k=1:(m-1)
Z(k)=(AGO(k)+AGO(k+1))/2; %Z(i) generates a sequence for the immediate mean of xi(1)
end
x11=x1(:,1:m);
X=x1(:,2:m)';% intercept matrix
Yn = A; %Yn is a constant term vector
Yn(1)=[];% starts from the second number, ie x(2), x(3)...
Yn=Yn';
%Yn=A(:,2:m)';
B=[-Z',X];
C=((B'*B)\(B'*Yn))';% is established by formula GM(1,n) model
a=C(1);
b=C(:,2:n+1);
F=[];
F(1)=A(1);
u=zeros(1,m);
for i=1:m
for j=1:n
u(i)=u(i)+(b(j)*x11(j,i));
end
end
for k=2:m
F(k)=(A(1)-u(k-1)/a)/exp(a*(k-1))+u(k-1)/a;
end
G=[];
G(1)=A(1);
for k=2:m
G(k)=F(k)-F(k-1);% Difference between the two to restore the original sequence, get the predicted data
end
Rik
Rik 2022년 8월 20일
Despite your flag, you editing away does not make your question not appropriate. It is just a rude thing to do.

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2022년 7월 24일
Can you dynamically create variables with numbered names like x1, x2, x3, etc.? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches.

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by