lundi 14 octobre 2019

AMPL. Error appears on some variables but no others

I need to define a sinc function https://en.wikipedia.org/wiki/Sinc_function in ampl. For that, I have to define an if-else. I have done it as in page 462 of the book https://ampl.com/BOOK/CHAPTERS/24-refman.pdf. However, once I run my program, an error message appears.

The sinc function has to be evaluated for all values of x. As said before, I have used an if-else statement with the condition evaluated for all values of i, which is what I use to count the number of steps that have already happen.

My error appears there, on the i as follows:

i is not defined context: var argA >>> =x1[i] <<< ;

I don't understand why since I have been using the same notation im previous lines and it works.

This is where I define the size of the step:

param n;

let n :=30;
set N  := {0..n by 1};

This is where I define the step and the variable x1, which is x.

var step >=0;
var x1 {N};
var SincA {N};

This is a piece of code where I use x1[i] and some other variables without any issue

var f1 {i in N} = w_x*x2[i]^3+u1[i];
var f2 {i in N} =  u2[i];
var midx1 {i in N1}     = 0.5*(x1[i]+x1[i+1]) + step/8*(f1[i]-f1[i+1]);

And lastly, here I show where the problem is

if abs(x1[i]) <=1e-8 then SincA[i]=1 else SincA[i]=sin(x1[i])/x1[i];

There is where the aforementioned error message appears.

I would like to know why the error message appears on the last line of code presented but not in the rest of them. As far as I understand, I am not using the variables in a different way.

Aucun commentaire:

Enregistrer un commentaire