# \[AMPL 24527\] AMPL question

**URL:** <https://discuss.ampl.com/t/ampl-24527-ampl-question/369>\
**Category:** Google Group Mirror\
**Created:** [February 11, 2023, 1:19pm UTC](https://discuss.ampl.com/t/ampl-24527-ampl-question/369 "2023-02-11T13:19:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcell\_Otvos](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Marcell\_Otvos](https://discuss.ampl.com/u/Marcell_Otvos)\
**Post date:** [February 11, 2023, 1:19pm UTC](https://discuss.ampl.com/t/ampl-24527-ampl-question/369/1 "2023-02-11T13:19:54Z")

</div>

Hi guys,

When I try to run the following code:  
#Part 0 declaration of parameters  
param n;  
param m;  
set N:=1…n; #number of bonds  
set M:=0…m; #number of years

param a{N}; #price of bonds  
param L{M}; #liabilities  
param d{M,N}; #payment structure

#Part 1 declaration of variables  
var x{N} \>=0, integer; #investment on bonds  
var z{M} \>=0; #cash on hand

#Part 2 objective function  
minimize cost: sum{j in N} a[j]\*x[j];

#Part 3 constraints

subject to initial: z[0]=0;  
subject to liability {i in M}: z[i-1]-z[i]+sum{j in N}d[i,j]\*x[j]\>=L[i];

I ran into the error saying

“Error executing “solve” command:  
error processing constraint liability[0]:  
invalid subscript z[-1]”

Can anyone help me solving this issue? I’m an absolute rookie to AMPL, any help is appreciated!

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [February 13, 2023, 4:05am UTC](https://discuss.ampl.com/t/ampl-24527-ampl-question/369/2 "2023-02-13T04:05:33Z")

</div>

Your “liability” constraints are defined by

```auto
subject to liability {i in M}: 
   z[i-1] - z[i] + sum{j in N} d[i,j] * x[j] >= L[i];

```

set M is 0…m, so there is a constraint liability[0] that is

`z[-1] - z[0] + sum {j in N} d[0,j] * x[j] >= L[0];`

But you have defined “var z{M} \>=0;”, so there is no variable z[-1], and as a result you are getting the “invalid subscript z[-1]” error. One way to fix this is to write instead

```auto
subject to liability {i in M diff {0}}:
   z[i-1] - z[i] + sum{j in N} d[i,j] * x[j] >= L[i];

```

so that AMPL does not generate a liability[0] constraint.
