I’m trying to use the following logic to assign parameters for Mn(n)
For n=1to 100 by 1;
Mn(1)=0, Mn(2)=0, is the initial value;
If n is odd, then Mn(n)=n2+ Mn( (n1)/2 ) + Mn( (n+1)/2 ) ;
If n is even, then Mn(n)=n2+ 2*Mn( (n)/2 );
I am trying to run the following model, but I am not successful. Can anyone help me achieve this goal?
Best Regards!
Hefeng
***=============================================================================
SETS
i component /i1*i100/ ;
Scalar
Count ;
Count=1;
Parameters
Nni(i)
;
Nni('i1')=0;
Nni('i2')=0;
while( (Count<=100),
if( (mod(Count,2)=1),
Nni(i)$(ord(i)=Count)=Count2+Nni(i)$(ord(i)=(Count1)/2)+Nni(i)$(ord(i)=(Count+1)/2) ;
else
Nni(i)$(ord(i)=Count)= Count2+2*Nni(i)$(ord(i)=Count/2) ;
);
Count=Count+1;
);
Display Nni ;
Logic assignment for parameters

 User
 Posts: 6
 Joined: 6 months ago
Logic assignment for parameters
Mr. Hefeng Zhai
School of Electrical Engineering, Shandong University, 17923 Jingshi Road, Jinan P.r.China 250061
School of Electrical Engineering, Shandong University, 17923 Jingshi Road, Jinan P.r.China 250061
Re: Logic assignment for parameters
This seems to work:
This gives:
Be aware that your recursion formula for n=1 accesses Mn(0) (Mn((11)/2) in the "odd" case). This is not problem for GAMS, this will evaluate just as 0. But you should think about this.
Michael
Code: Select all
set n /1*10/;
parameter Mn(n) /#n 0/;
loop(n,
Mn(n)$(mod(n.val,2)=1) = n.val2 + Mn(n((n.val+1)/2)) + Mn(n((n.val1)/2));
Mn(n)$(mod(n.val,2)=0) = n.val2 + 2*Mn(n(n.val/2));
);
display Mn;
Code: Select all
 7 PARAMETER Mn
1 1.000, 2 2.000, 3 2.000, 4 2.000, 5 1.000, 7 1.000
8 2.000, 9 4.000, 10 6.000
Michael

 User
 Posts: 6
 Joined: 6 months ago
Re: Logic assignment for parameters
Dear Michael,bussieck wrote: ↑6 months agoThis seems to work:
This gives:Code: Select all
set n /1*10/; parameter Mn(n) /#n 0/; loop(n, Mn(n)$(mod(n.val,2)=1) = n.val2 + Mn(n((n.val+1)/2)) + Mn(n((n.val1)/2)); Mn(n)$(mod(n.val,2)=0) = n.val2 + 2*Mn(n(n.val/2)); ); display Mn;
Be aware that your recursion formula for n=1 accesses Mn(0) (Mn((11)/2) in the "odd" case). This is not problem for GAMS, this will evaluate just as 0. But you should think about this.Code: Select all
 7 PARAMETER Mn 1 1.000, 2 2.000, 3 2.000, 4 2.000, 5 1.000, 7 1.000 8 2.000, 9 4.000, 10 6.000
Michael
Thank you very much for your help and advice！
Best Regards
Hefeng

 User
 Posts: 4
 Joined: 1 month ago
Re: Logic assignment for parameters
Before proceeding to the study of logical operators, I assembled models compiled in the early stages of GAMS development and used them in the examples' library.
I already had thoughts about using the help of programmers with many years of experience in these areas https://www.assignmentexpert.com/programming, since the approach I took to study has a little drawback: the initial "usability" to the package may take a certain amount of time (this is actually my initial experience).
However, modern appearance still has a developed,
fully functional Windowslike interface and therefore I hope that this problem will be easily overcome by me shortly.
Thanks for the wise advice!
Regards, Myron
I already had thoughts about using the help of programmers with many years of experience in these areas https://www.assignmentexpert.com/programming, since the approach I took to study has a little drawback: the initial "usability" to the package may take a certain amount of time (this is actually my initial experience).
However, modern appearance still has a developed,
fully functional Windowslike interface and therefore I hope that this problem will be easily overcome by me shortly.
Thanks for the wise advice!
Regards, Myron