# Grape phase.m

From Spinach Documentation Wiki

Cost function for optimal control using the GRAPE algorithm.

## Syntax

[fidelity,gradient,hessian]=grape_phase(phi_profile,amp_profile,spin_system)

## Description

Returns fidelity, gradient and Hessian for a given waveform, specified in polar coordinates. Only the phase channel gradient is returned, the amplitude profile is taken as a given.

## Arguments

amp_profile - set of control pulse amplitudes from an amplitude- phase description. phi_profile - set of control pulse phases from an amplitude-phase description.

## Returns

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. gradient - 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. hessian - Hessian of the fidelity with respect to the control sequence. When penalty methods are specified, gradi- ent is returned as an array separating penalty Hes- sians from the fidelity Hessian.

## Examples

A typical call would be from an optimisation function (see examples/optimal_control):

% Optimisation parameters optim.method='lbfgs'; % Optimisation method optim.extremum='maximum'; % Extremum type % Use constant amplitude profile amp_profile=ones(size(guess)); % Run the optimization fminnewton(@grape_phase,guess,optim,amp_profile,spin_system);

## Notes

The fidelity, the gradient and the Hessian may be supplied to any optimisation routine, including those in the Optimisation Toolbox of Matlab.

## See also

grape.m, grape_xy.m, ensemble.m, optimcon.m

*Version 2.0, authors: Ilya Kuprov, David Goodwin*