%% Convert DAE System to a Function Handle
%% 1

syms x1(t) x2(t) a b r(t)
eqs = [diff(x1(t),t) == a*x1(t) + b*x2(t)^2,...
       x1(t)^2 + x2(t)^2 == r(t)^2];
vars = [x1(t), x2(t)];

%
%% 2

f = daeFunction(eqs, vars, a, b, r(t))

%
%% 3

a = -0.6;
b = -0.1;
r = @(t) cos(t)/(1 + t^2);
F = @(t, Y, YP) f(t,Y,YP,a,b,r(t));

%
%% 4

t0 = 0;
y0 = [-r(t0)*sin(0.1); r(t0)*cos(0.1)];
yp0 = [a*y0(1) + b*y0(2)^2; 1.234];

%
%% 5

ode15i(F, [t0, 1], y0, yp0)

% Copyright 2015 The MathWorks, Inc.