Some Common Errors
Coding syntax
Failing to end statements with a semicolon
Using an assignment operator when a comparison operator was desired
if (x = 1.)
{
}
Should be:
if (x == 1.)
{
}
Modeling code
Data not read in correctly. Since
it is very common to use values read from data files to dimension arrays and perform
various declarations, it is EXTREMELY important to ensure that data have been read as
intended.
Assigning a scalar value to an array:
in ADModel code define:
number x;
vector y(1,10);
vector z(1,10);
x = 3.15;
for (int i = 1; i <= 10; i++)
{
z = double(i);
}
y = z;
z = x;
cout << z << endl;
cout << y << endl;
cout << x << endl;
This code will return
3.15 3.15 3.15 3.15 3.15 3.15 3.15 3.15 3.15
1 2 3 4 5 6 7 8 9 10
3.15
Inadvertent use of matrix operations
in ADModel code define:
matrix A(1,10,1,10);
matrix B(1,10,1,10);
matrix C(1,10,1,10);
(say that A and B have been assigned values and that C should be set to the
element-wise product of A and B)
Incorrect:
C = A * B; // This is a matrix multiplication operation
Correct:
C = elem_prod(A , B);
// elem_prod is a function defined in the Autodif library
Up
|