Function File: [ dotx, dotxdx, u] = pendulum (t, x, opt)
Implements a general pendulum.
q'' + (g/l)*sin(q) + d*q' = f(t,q,q')where q is the angle of the pendulum and q' its angular velocity
This function can be used with the ODE integrators.
INPUTS
t: Time. It can be a scalar or a vector of length
nT
.x: State space vector. An array of size
2xnT
, wherenT
is the number of time values given. The first row corresponds to the configurations of the system and the second row to its derivatives with respect to time.opt: An options structure. See the complementary function
setpendulum
. The structure containing the fields:
Coefficients
: Contains the coefficients (g/l).
Damping
: Contains the coefficient d.
Actuation
: An optional field of the structure. If it is present, it defines the function f(t,q,q'). It can be a handle to a function of the form f = func(t,x,opt) or it can be a1xnT
vector.OUTPUT
dotx: Derivative of the state space vector with respect to time. A
2xnT
array.dotxdx: When requested, it contains the Jacobian of the system. It is a multidimensional array of size
2x2xnT
.u: If present, the function returns the inputs that generate the sequence of state space vectors provided in x. To do this the functions estimates the second derivative of q using spline interpolation. This implies that there be at least 2 observations of the state vector x, i.e.
nT >= 2
. Otherwise the output is empty.