# getx0

Map initial conditions from a `mechss` object to a `sparss` object

## Syntax

``x0 = getx0(sys,q0,dq0)``
``x0 = getx0(sys,q1,q2)``

## Description

example

````x0 = getx0(sys,q0,dq0)` computes a matching initial condition `x0` for an equivalent sparse first-order model using the initial conditions for displacement `q0` and velocity `dq0` from the continuous-time sparse second-order model `sys`. You can omit the second and third input arguments when `q0` and `dq0` are zero. The output, $x0=\left[\begin{array}{c}q0\\ dq0\end{array}\right]=\left[\begin{array}{c}q\left(0\right)\\ \frac{dq}{dt}\left(0\right)\end{array}\right]$ when the `[sys.M;sys.G]` matrices has no zero columns.In general, the states of the `sparss` model is $x=\left[\begin{array}{c}q\\ dq\left(jnz\right)\end{array}\right]$ where jnz are the indices of the nonzero columns of `[sys.M;sys.G]`. The resulting number of states nx is ${n}_{x}={n}_{q}+\text{numel}\left(jnz\right)\le 2{n}_{q}$ where nq is the number of nodes in the `mechss` object `sys`.```

example

````x0 = getx0(sys,q1,q2)` computes a matching initial condition using initial values `q1 = q[k]` and `q2 = q[k+1]` for discrete-time systems. The second and third input arguments can be omitted when `q0` and `dq0` are zero. The output, $x0=\left[\begin{array}{c}q1\\ q2\end{array}\right]=\left[\begin{array}{c}q\left[k\right]\\ q\left[k+1\right]\end{array}\right]$ when the `M` and `G` matrices of the `mechss` model `sys` has no zero columns.```

## Examples

collapse all

For this example, consider a continuous-time sparse second-order model with 108 nodes. The row vectors `q0` and `dq0` are the initial conditions for displacement and velocity, respectively. The vectors `q0` and `dq0` have the same size as the number of nodes in `sys`.

Load the data in `sparseSOC.mat` and find the initial conditions for an equivalent sparse first-order model using `getx0`.

```load('sparseSOC.mat','sys','q0','dq0'); x0 = getx0(sys,q0,dq0); size(x0)```
```ans = 1×2 216 1 ```

In this case, vector `x0` contains 216 states, since $x0=\left[\begin{array}{c}q0\\ dq0\end{array}\right]$.

For this example, consider a discrete-time sparse second-order model with 7102 nodes. The row vectors `q1` and `q2` are the initial conditions for `k` and `k+1` time steps, respectively. The vectors `q1` and `q2` have the same size as the number of nodes in `sys`.

Load the data in `sparseSOD.mat` and find the initial conditions for an equivalent discrete-time sparse first-order model using `getx0`.

```load('sparseSOD.mat','sys','q1','q2'); x0 = getx0(sys,q1,q2); size(x0)```
```ans = 1×2 14204 1 ```

In this case, vector `x0` contains 14204 states since $x0=\left[\begin{array}{c}q1\\ q2\end{array}\right]$.

## Input Arguments

collapse all

Continuous-time or discrete-time sparse second-order model to be converted to a sparse first-order model, specified as a `mechss` model object.

For more information, see the `mechss` reference page.

Initial values of the displacement vector, specified as a row vector of length `Nq`, where `Nq` is the number of states in the continuous-time second-order sparse model `sys`.

Initial values of the velocity vector, specified as a row vector of length `Nq`, where `Nq` is the number of states in the continuous-time second-order sparse model `sys`.

Initial values of state vector at `k`, specified as a row vector of length `Nq`, where `Nq` is the number of states in the continuous-time second-order sparse model `sys`. In other words, `q1 = q[k]`.

Initial values of state vector at `k`, specified as a row vector of length `Nq`, where `Nq` is the number of states in the continuous-time second-order sparse model `sys`. In other words, `q2 = q[k+1]`.

## Output Arguments

collapse all

Mapped initial conditions for the equivalent sparse first-order model, returned as an array of doubles. When the mass matrix `M` and the velocity-to-output matrix `G` of the `mechss` object contains no zero columns, then:

• $x0=\left[\begin{array}{c}q0\\ dq0\end{array}\right]=\left[\begin{array}{c}q\left(0\right)\\ \frac{dq}{dt}\left(0\right)\end{array}\right]$ for continuous-time systems.

• $x0=\left[\begin{array}{c}q1\\ q2\end{array}\right]=\left[\begin{array}{c}q\left[k\right]\\ q\left[k+1\right]\end{array}\right]$ for discrete-time systems.

## Version History

Introduced in R2020b