15.11.2014 Views

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Initial Value Problems for ODEs and DAEs<br />

function hb1dae<br />

%HB1DAE Stiff differential-algebraic equation (DAE)<br />

% A constant, singular mass matrix<br />

M = [1 0 0<br />

0 1 0<br />

0 0 0];<br />

% Use an inconsistent initial condition to test initialization.<br />

y0 = [1; 0; 1e-3];<br />

tspan = [0 4*logspace(-6,6)];<br />

% Use the LSODI example tolerances. The 'MassSingular' property<br />

% is left at its default 'maybe' to test the automatic detection<br />

% <strong>of</strong> a DAE.<br />

options = odeset('Mass',M,'RelTol',1e-4,...<br />

'AbsTol',[1e-6 1e-10 1e-6],'Vectorized','on');<br />

[t,y] = ode15s(@f,tspan,y0,options);<br />

y(:,2) = 1e4*y(:,2);<br />

semilogx(t,y);<br />

ylabel('1e4 * y(:,2)');<br />

title(['Robertson DAE problem with a Conservation Law, '...<br />

'solved by ODE15S']);<br />

xlabel('This is equivalent to the stiff ODEs coded in HB1ODE.');<br />

% --------------------------------------------------------------<br />

function out = f(t,y)<br />

out = [ -0.04*y(1,:) + 1e4*y(2,:).*y(3,:)<br />

0.04*y(1,:) - 1e4*y(2,:).*y(3,:) - 3e7*y(2,:).^2<br />

y(1,:) + y(2,:) + y(3,:) - 1 ];<br />

5-37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!