%% Compute Consistent Initial Conditions for Implicit Equations
% Consider the implicit system of equations
% \begin{array}{cc} 0 &= 2y'_1 - y_2\\ 0 &=y_1+y_2 \end{array}
% These equations are straightforward enough that it is simple to read off consistent initial conditions for the variables. For example, if you fix y_1 = 1, then y_2=-1 according to the second equation and y'_1 = -1/2 according to the first equation. Since these values of y_1, y'_1, and y_2 satisfy the equations, they are consistent.
% Confirm these values by using decic to compute consistent initial conditions for the equations, fixing the value y_1 = 1. 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,[])

% Copyright 2012 The MathWorks, Inc.