pockit.base.variablebase
Value matrix with interpolation nodes x_old and evaluation nodes
x_new.
Derivative matrix with interpolation nodes x_old and evaluation
nodes x_new.
Provide indexed access to a sequence of array slices.
Arguments:
- data: The underlying data array.
- l_index: The left indices of each batch.
- r_index: The right indices of each batch (exclusive).
Optimization variable for a discretized phase.
A Variable exposes its data both as a flat array for solvers and through
convenient accessors for individual state and control variables. It also
provides interpolation matrices for plotting and mesh adaptation.
Users normally create instances with constant_guess or linear_guess
and then adjust the initial guess as needed.
Arguments:
- phase: The
Phaseobject to create theVariablefor. - data: The underlying data array.
Return the value interpolation matrix for the state variables at the
output time nodes t.
Arguments:
- t: Time points for output.
Returns:
The interpolation matrix in the compressed sparse row format.
Examples:
Plot the first state variable at the output time nodes
t_out:>>> t_out = np.linspace(v.t_0, v.t_f, 100) >>> V_x = v.V_x(t_out) >>> x_out_0 = V_x @ v.x[0] >>> plt.plot(t_out, x_out_0)
Return the value interpolation matrix for the control variables at
the output time nodes t.
Arguments:
- t: Time points for output.
Returns:
The interpolation matrix in the compressed sparse row format.
Examples:
Plot the first control variable at the output time nodes
t_out:>>> t_out = np.linspace(v.t_0, v.t_f, 100) >>> V_u = v.V_u(t_out) >>> u_out_0 = V_u @ v.u[0] >>> plt.plot(t_out, u_out_0)
Return the physical-time derivative matrix for the state variables.
Arguments:
- t: Time points for output.
Returns:
The derivative matrix in the compressed sparse row format.
Examples:
Plot the derivative of the first state variable at the output time nodes
t_out:>>> t_out = np.linspace(v.t_0, v.t_f, 100) >>> D_x = v.D_x(t_out) >>> dx_out_0 = D_x @ v.x[0] >>> plt.plot(t_out, dx_out_0)
Return the physical-time derivative matrix for the control variables.
Arguments:
- t: Time points for output.
Returns:
The derivative matrix in the compressed sparse row format.
Examples:
Plot the derivative of the first control variable at the output time nodes
t_out:>>> t_out = np.linspace(v.t_0, v.t_f, 100) >>> D_u = v.D_u(t_out) >>> du_out_0 = D_u @ v.u[0] >>> plt.plot(t_out, du_out_0)
The underlying data array.
Typically used to pass to the solver.
The time interpolation nodes of the state variables.
The time interpolation nodes of the control variables.
Adapt the Variable to a Phase with a different mesh and
interpolation degree.
Return a new Variable object without changing the current one.
Arguments:
- phase: The
Phasewith a different mesh and interpolation degree to adapt to.
Returns:
A new
Variableobject adapted with values interpolated from the current one and compatible with the discretization scheme of the newPhase.
Return a Variable with constant guesses for a Phase.
Fixed boundary values are preserved, and all other variables are set to
value. The returned object can be adjusted before it is passed to a
solver.
Arguments:
- Variable: Concrete
Variableclass to instantiate. - phase: The
Phaseto guess for. - value: The constant value to guess.
Returns:
A
Variablewith constant guesses for the givenPhase.
Return a Variable with linear guesses for a Phase.
Fixed boundary values are preserved. Missing boundary values are replaced
by default, and state values between the boundaries are interpolated
linearly. The returned object can be adjusted before it is passed to a
solver.
Arguments:
- Variable: Concrete
Variableclass to instantiate. - phase: The
Phaseto guess for. - default: The default value to guess.
Returns:
A
Variablewith linear guesses for the givenPhase.