# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# decic

Compute consistent initial conditions for `ode15i`

## Syntax

``````[y0_new,yp0_new] = decic(odefun,t0,y0,fixed_y0,yp0,fixed_yp0)``````
``````[y0_new,yp0_new] = decic(odefun,t0,y0,fixed_y0,yp0,fixed_yp0,options)``````
``````[y0_new,yp0_new,resnrm] = decic(___)``````

## Description

example

``````[y0_new,yp0_new] = decic(odefun,t0,y0,fixed_y0,yp0,fixed_yp0)``` uses `y0` and `yp0` as guesses for the initial conditions of the fully implicit function `odefun`, holds the components specified by `fixed_y0` and `fixed_yp0` as fixed, then computes values for the nonfixed components. The result is a complete set of consistent initial conditions. The new values `yo_new` and `yp0_new` satisfy ```odefun(t0,y0_new,yp0_new) = 0``` and are suitable to be used as initial conditions with `ode15i`.```
``````[y0_new,yp0_new] = decic(odefun,t0,y0,fixed_y0,yp0,fixed_yp0,options)``` also uses the options structure `options` to specify values for `AbsTol` and `RelTol`. Create the options structure using `odeset`.```
``````[y0_new,yp0_new,resnrm] = decic(___)``` returns the norm of `odefun(t0,y0_new,yp0_new)` as `resnrm`. If the norm seems unduly large, then use `options` to decrease the relative error tolerance `RelTol`, which has a default value of `1e-3`.```

## Examples

collapse all

Consider the implicit system of equations

These equations are straightforward enough that it is simple to read off consistent initial conditions for the variables. For example, if you fix , then according to the second equation and according to the first equation. Since these values of , , and satisfy the equations, they are consistent.

Confirm these values by using `decic` to compute consistent initial conditions for the equations, fixing the value . Use guesses of `y0 = [1 0]` and `yp0 = [0 0]`, which do not satisfy the equations and are thus inconsistent.

```odefun = @(t,y,yp) [2*yp(1)-y(2); y(1)+y(2)]; t0 = 0; y0 = [1 0]; yp0 = [0 0]; [y0,yp0] = decic(odefun,t0,y0,[1 0],yp0,[])```
```y0 = 1 -1 ```
```yp0 = -0.5000 0 ```

Use `decic` to compute consistent initial conditions for the Weissinger implicit ODE. `decic` holds fixed the initial value for y(t0) and computes a consistent initial value for y'(t0). The `weissinger` function evaluates the residual of the implicit ODE.

```t0 = 1; y0 = sqrt(3/2); yp0 = 0; [y0,yp0] = decic(@weissinger,t0,y0,1,yp0,0);```

Use the result returned by `decic` with `ode15i` to solve the ODE. Plot the numerical solution, `y`, against the analytical solution, `ytrue`.

```[t,y] = ode15i(@weissinger,[1 10],y0,yp0); ytrue = sqrt(t.^2 + 0.5); plot(t,y,t,ytrue,'o')```

## Input Arguments

collapse all

Functions to solve, specified as a function handle that defines the functions to be integrated. `odefun` represents the system of implicit differential equations that you want to solve using `ode15i`.

The function `f = odefun(t,y,yp)`, for a scalar `t` and column vectors `y` and `yp`, must return a column vector `f` of data type `single` or `double` that corresponds to $f\left(t,y,y\text{'}\right)$. `odefun` must accept all three input arguments, `t`, `y`, and `yp` even if one of the arguments is not used in the function.

For example, to solve $y\text{'}-y=0$, use this function.

```function f = odefun(t,y,yp) f = yp - y;```

For a system of equations, the output of `odefun` is a vector. Each equation becomes an element in the solution vector. For example, to solve

`$\begin{array}{l}y{\text{'}}_{1}-{y}_{2}=0\\ y{\text{'}}_{2}+1=0\text{\hspace{0.17em}},\end{array}$`

use this function.

```function dy = odefun(t,y,yp) dy = zeros(2,1); dy(1) = yp(1)-y(2); dy(2) = yp(2)+1;```

For information on how to provide additional parameters to the function `odefun`, see Parameterizing Functions.

Example: `@myFcn`

Data Types: `function_handle`

Initial time, specified as a scalar. `decic` uses the initial time to compute consistent initial conditions that satisfy ```odefun(t0,y0_new,yp0_new) = 0```.

Data Types: `single` | `double`

Initial guesses for `y`-components, specified as a vector. Each element in `y0` specifies an initial condition for one dependent variable ${y}_{n}$ in the system of equations defined by `odefun`.

Data Types: `single` | `double`

`y`-components to hold fixed, specified as a vector of 1s and 0s, or as `[]`.

• Set `fixed_y0(i) = 1` if no change is permitted in the guess for `y0(i)`.

• Set `fixed_y0 = []` if any entry can be changed.

You cannot fix more than `length(yp0)` components. Depending on the specific problem, it is not always possible to fix certain components of `y0` or `yp0`. It is a best practice not to fix more components than is necessary.

Initial guesses for `y'`-components, specified as a vector. Each element in `yp0` specifies an initial condition for one differentiated dependent variable $y{\text{'}}_{n}$ in the system of equations defined by `odefun`.

Data Types: `single` | `double`

`y'`-components to hold fixed, specified as a vector of 1s and 0s, or as `[]`.

• Set `fixed_yp0(i) = 1` if no change is permitted in the guess for `yp0(i)`.

• Set `fixed_yp0 = []` if any entry can be changed.

You cannot fix more than `length(yp0)` components. Depending on the specific problem, it is not always possible to fix certain components of `y0` or `yp0`. It is a best practice not to fix more components than is necessary.

Option structure, specified as a structure array. Use the `odeset` function to create or modify the option structure. The relevant options for use with the `decic` function are `RelTol` and `AbsTol`, which control the error thresholds used to compute the initial conditions.

Example: `options = odeset('RelTol',1e-5)`

Data Types: `struct`

## Output Arguments

collapse all

Consistent initial conditions for `y0`, returned as a vector. If the value of `resnrm` is small, then `yo_new` and `yp0_new` satisfy ```odefun(t0,y0_new,yp0_new) = 0``` and are suitable to be used as initial conditions with `ode15i`.

Consistent initial conditions for `yp0`, returned as a vector. If the value of `resnrm` is small, then `yo_new` and `yp0_new` satisfy ```odefun(t0,y0_new,yp0_new) = 0``` and are suitable to be used as initial conditions with `ode15i`.

Norm of residual, returned as a vector. `resnrm` is the norm of `odefun(t0,y0_new,yp0_new)`.

• A small value of `resnrm` indicates that `decic` successfully computed consistent initial conditions that satisfy `odefun(t0,y0_new,yp0_new) = 0`.

• If the value of `resnrm` is large, try adjusting the error thresholds `RelTol` and `AbsTol` using the `options` input.

## Tips

• The `ihb1dae` and `iburgersode` example files use `decic` to compute consistent initial conditions before solving with `ode15i`. Type ```edit ihb1dae``` or `edit iburgersode` to view the code.

• You can additionally use `decic` to compute consistent initial conditions for DAEs solved by `ode15s` or `ode23t`. To do this, follow these steps.

1. Rewrite the system of equations in fully implicit form `f(t,y,y') = 0`.

2. Call `decic` to compute consistent initial conditions for the equations.

3. Specify `y0_new` as the initial condition in the call to the solver, and specify `yp_new` as the value of the `InitialSlope` option of `odeset`.