%% Sparse Matrices
%% 1

syms x1(t) x2(t)

a = -0.6;
b = -0.1;
r = @(t) cos(t)/(1 + t^2);

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)];
[M, F] = massMatrixForm(eqs, vars);
M = odeFunction(M, vars, 'Sparse', true);
F = odeFunction(F, vars);
t0 = 0;
y0 = [-r(t0)*sin(0.1); r(t0)*cos(0.1)];
yp0 = [a*y0(1) + b*y0(2)^2; 1.234];
opt = odeset('mass', M, 'InitialSlope', yp0);

%
%% 2

ode15s(F, [t0, 1], y0, opt)

% Copyright 2012 The MathWorks, Inc.