From QERM Wiki
(Difference between revisions)


Line 121: 
Line 121: 
  <code> bolinha.initialize() </code>  Initializes (sets all elements equal to zero) the object bolinha    <code> bolinha.initialize() </code>  Initializes (sets all elements equal to zero) the object bolinha 
 }   } 
 +  [http://paperswriting.com/ essay papers] 
Revision as of 07:52, 9 April 2010
ADMB Handy operations and functions (aka ADMB cheat sheet)
Adapted from a Word document written by Carolina MinteVera.
Let V, X, Y be vectors and v_{i}, x_{i}, y_{i} be the elements of the vectors.
Let M, N, A be matrices and m_{ij}, n_{ij}, a_{ij} be the elements of the matrices.
Let α be a scalar.
Matrix and vector operations
Operation 
Math notation 
ADMB slow code 
ADMB fast code

Sum of two vectors 
v_{i} = x_{i} + y_{i} 
V = X + Y 
X+=Y

Sum of scalar to a vector 
v_{i} = x_{i} + α 
V = X + nu 
X+=nu

Sum of two matrices 
a_{ij} = m_{ij} + n_{ij} 
A = M + N 

Sum of a scalar to a matrix 
a_{ij} = m_{ij} + α 
A = M +alpha 
M+=alpha

Subtract two vectors 
v_{i} = x_{i} − y_{i} 
V = X  Y 
X=Y

Subtract a scalar from a vector 
v_{i} = x_{i} − α 
V=Xalpha 
X=alpha

Subtract a scalar from a matrix 
v_{i} = x_{i} − α 
A=Malpha 
M=alpha

Subtract two matrices 
a_{ij} = m_{ij} − n_{ij} 
A=MN 
M=N

Vector dot product 

alpha=X*Y 

Outer product of two vectors 
m_{ij} = x_{i}y_{j} 
M=outer_prod(X,Y) 

Multiply a scalar by a vector 
x_{i} = αy_{i} 
X=alpha*Y 
Y*=alpha

Multiply a vector by a scalar 
x_{i} = y_{i}α 
X=Y*alpha 

Multiply a scalar by a matrix 
m_{ij} = αa_{ij} 
A=alpha*M 
M*=alpha

Multiply a vector by a matrix 

X=Y*M 

Multiply a matrix by a vector 

X=M*Y 

Multiply two matrices 

A=M*N 

Division of vector by scalar 
y_{i} = x_{i} / α 
Y=X/alpha 
X/=alpha

Division of scalar by a vector 
y_{i} = α / x_{i} 
Y=alpha/X 

Division of a matrix by a scalar 
m_{ij} = a_{ij} / α 
M=N/alpha 

Element–wise (ew) operations in a matrix or vector object
Operation [need objects of the same dimension] 
Math notation 
ADMB code

Vectors ew multiplication 
v_{i} = x_{i}y_{i} 
V=elem_prod(X,Y)

Vectors ew division 
v_{i} = x_{i} / y_{i} 
V=elem_div(X,Y)

Matrices ew multiplication 
m_{ij} = a_{ij}n_{ij} 
M=elem_prod(A,N)

Matrices ew division 
m_{ij} = a_{ij} / n_{ij} 
M=elem_div(A,N)

Vectors ew multiplication 
v_{i} = x_{i}y_{i} 
V=elem_prod (X,Y)

Other matrix or vector operations
Operation 
Math notation 
ADMB code

Norm of a vector 

alpha=norm(V)

Norm square of a vector 

alpha=norm2(V)

Norm of a matrix 

alpha=norm(M)

Norm square of a matrix 

alpha=norm2(M)

Sum over elements of a vector 

alpha=sum(V)

Row sums of a matrix object 

X=rowsum(M)

Column sum of a matrix object 

Y=colsum(M)

Concatenation 
X = (x_{1},x_{2},x_{3}),Y = (y_{1},y_{2}),V = (x_{1},x_{2},x_{3},y_{1},y_{2}) 
V=X&Y

Still more matrix or vector operations
Operation 
ADMB code

Determinant (must be a square matrix cols=rows) 
alpha=det(M)

Logarithm of the determinant? (must be a square matrix cols=rows), sgn is an integer. Not explained in the manual, but used in the codes. 
alpha=ln_det(M,sgn)

Inverse (must be a square matrix cols=rows) 
N=inv(M)

Minimum value of a vector object 
alpha=min(V)

Maximum value of a vector object 
alpha=max(V)

Eigenvalues of a symmetric matrix 
V=Eigenvalues(M)

Eigenvectors of a symmetric matrix 
N=eigenvectors(M)

Identity matrix function 
M=identity_matrix(int min, int max)

Useful functions
Function 
Action

current_phase() 
return an integer that is the value of the current phase

last_phase() 
return a binary: "true" if the current phase is the last phase and "false" (=0) otherwise

Active(Par) 
return a binary: "true" if the parameter Par is active in the current phase and "false" (=0) otherwise

mceval_phase() 
return a binary: "true" if the current phase is the mceval phase and "false" (=0) otherwise

bolinha.initialize() 
Initializes (sets all elements equal to zero) the object bolinha

essay papers