# Difference between revisions of "Penalty.m"

This describes penalty terms for pulse waveforms. Returns the penalty function and its gradient for the waveform, which should be supplied as row vector or a horizontal stack thereof. Syntax:

    [penalty_term,penalty_grad,penalty_hess]=...
penalty(waveform,type,floor_bound,ceiling_bound);


If a stack of waveforms is supplied, individual rows of the stack are treated as independent and the penalties are summed together. The penalty terms are usually evaluated within the cost_function passed as a nested function with its handle to fminnewton.m.

# Inputs

 'waveform' pulse waveform, supplied as row vector or a horizontal stack thereof. type='DNS' derivative norm square penalty term, designed to favour smooth waveforms over jagged ones. type='NS' norm square penalty term, designed to favour low‐power wave forms over high‐power ones. type='SNS' spillout norm square penalty term, NS penalty applied to any part of the waveform whose value is outside the floor and ceiling bounds. 'floor_bound' lower bound waveform used in the SNS penalty function. 'ceiling_bound' upper bound waveform used in the SNS penalty function.

If a stack of waveforms is supplied, individual rows of the stack are treated as independent and the penalties are summed together. The waveforms on different channels are assumed to be stored in the rows of the input array. The Hessian elements correspond to the elements of the waveform array ordered as:

    [X1 Y1 Z1 X2 Y2 Z2 ... Xn Yn Zn]


where X,Y,Z are different control channels and the index enumerates the time discretization points. Gradient dimensions and element order are the same as the input waveform dimensions and element order.

# Outputs

 'penalty_term' value of the penalty term. 'penalty_grad' gradient of the penalty term with respect to the waveform vector. 'penalty_hess' Hessian of the penalty term with respect to the waveform vector.