assign parameters in sequence Topic is solved

Problems with modeling
Post Reply
Bingo LI
User
User
Posts: 21
Joined: 6 years ago

assign parameters in sequence

Post by Bingo LI »

Hello all,
I'm working on assigning a parameter in sequence. In my purpose, the sequence of the parameters is:
i=1
P_1= 13
i=2
P_1= 24
i=3
P_1= 15.

However. the result in my programm is
i=1
P_1= 13
i=2
P_1=1 13
2 24
i=3
P_1=1 13
2 24
3 15.

The code is attached. Could someone help me with this problem? thank you.
Attachments
Untitled_2.gms
(445 Bytes) Downloaded 228 times
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: assign parameters in sequence

Post by Renger »

Hi
You are assigning the value to a vector (P_1(ii)) and not to a scalar P_1=P_rec(ii). So,just replace P_1(ii) in your loop by P_1.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Bingo LI
User
User
Posts: 21
Joined: 6 years ago

Re: assign parameters in sequence

Post by Bingo LI »

Thanks for your answer.
However, a vector (P_1(ii)) is needed as there are other variables in my programm.
The purpose of this programm is that I want to eliminate P_1(1) when ii=2.
Could it be done?
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: assign parameters in sequence

Post by Renger »

Hi
I assume that after assigning the value to P_1(ii) you have some more code that uses the single-valued P_1(ii). You could do this by setting all the values to zero before you assign the single-value and set them after your additional code once again to zero.

Code: Select all

loop (ii,
   P_1(ii) = 0;
   subi(ii)=yes;
   P_1(ii)=P_rec(ii);
* your other code using the P_1(ii) single value
   display subi,P_1;
   subi(ii)=no;
   P_1(ii) = 0;
);
This gives:

Code: Select all

1
----     27 PARAMETER P_1  
1 13.000
----     27 SET subi  
2
----     27 PARAMETER P_1  
2 24.000
----     27 SET subi  
3
----     27 PARAMETER P_1  
3 15.000
I hope this helps
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Bingo LI
User
User
Posts: 21
Joined: 6 years ago

Re: assign parameters in sequence

Post by Bingo LI »

Hi Renger,
It solves my problem perfectly.
Thank you.
Li
Post Reply