# grape_curv.m

Cost function for optimal control using the GRAPE algorithm. Returns fidelity and gradient for a given waveform, specified in arbitrary curvilinear coordinates.

## Syntax

[traj_data,fidelity,df_du]=grape_curv(waveform_u,u2x,dx_du,spin_system)

## Arguments

waveform_u - pulse waveform in curvilinear coordinates with indi- vidual coordinates in columns and time in rows u2x - a handle to a function that takes a column of curvi- linear coordinates and returns a column of coeffici- ents in front of the control operators dx_du - a handle to a function that takes a column of curvi- linear coordinates and returns the Jacobian matrix with the following structure: [dx(1)_du(1) dx(2)_du(1) dx(3)_du(1) ... dx(1)_du(2) dx(2)_du(2) dx(3)_du(2) ... ... ... ... ...]

## Outputs

traj_data - system trajectory data structure used for visualisa- tion and progress reports fidelity - figure of merit for the overlap of the current state of the system and the desired state(s). When penalty methods are specified, fidelity is returned as an ar- ray separating the penalties from the simulation fidelity. df_du - gradient of the fidelity with respect to the control sequence. When penalty methods are specified, gradi- ent is returned as an array separating penalty gra- dients from the fidelity gradient.

## Notes

Penalities are computed using the rectilinear representation.

## See also

*Version 2.7, authors: Ilya Kuprov*