Error 148 Topic is solved

Problems with syntax of GAMS
Post Reply
ltx
User
User
Posts: 4
Joined: 2 years ago

Error 148

Post by ltx »

Hello Everyone,
I had an error148 when I tried to run my code. It's really confusing, and I can't find the problem with my equation expression. Thanks for your help!

sets

t periods /0*50/

;
alias (t,tt);

parameters
a demand curve intercept /8/
b demand curve slope /0.4/
C marginal extraction cost /2/
r discount rate /0.05/
Q total resource available /40/
lambda marginal user cost
;


variables
x(t) quantities extracted per period
p(t) price of extracted resource per period
nb present value of net benefit
;

equations
obj_func objective function
dem_curve(t) demand curve
cons total available resource
;

obj_func.. nb =e= sum(t, (exp(-r*t)) * (x(t)*(a-((0.5*b)*x(t)) -c)));
dem_curve(t).. p(t) =e= a - (b*x(t));
cons.. Q =e= sum(t,x(t));

model extraction /obj_func, dem_curve, cons/;
* set lower bounds to avoid errors and ensure a meaningful solution
x.lo = 0;
p.lo = 0;
solve extraction using nlp maximizing nb;
lambda(t)$(x.l(t) > 0) = exp(-r*t)*(a - b*x(t)-c);
display lambda;
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Error 148

Post by abhosekar »

Please use code blocks when you provide code fragments.

I see the issue. You are using r*t
but t is a set. So what do you mean by r*t? You could define your set as t0*t50 and your equation would hold no meaning. This is why you see this error.

Two ways to fix.
1. If you want to use the value in the set you can do r*t.val (assuming
2. But a cleaner way would be to define a parameter tval that has values 0 to 50 values and use that parameter in your equations. There are few more error in your code but you can fix those by looking at GAMS documentation. https://www.gams.com/latest/docs/UG_FixingErrors.html

- Atharv
ltx
User
User
Posts: 4
Joined: 2 years ago

Re: Error 148

Post by ltx »

Thanks so much. It works.
Post Reply