1 %# Copyright (C) 2008-2012, Thomas Treichl <treichl@users.sourceforge.net>
2 %# OdePkg - A package for solving ordinary differential equations and more
4 %# This program is free software; you can redistribute it and/or modify
5 %# it under the terms of the GNU General Public License as published by
6 %# the Free Software Foundation; either version 2 of the License, or
7 %# (at your option) any later version.
9 %# This program is distributed in the hope that it will be useful,
10 %# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 %# GNU General Public License for more details.
14 %# You should have received a copy of the GNU General Public License
15 %# along with this program; If not, see <http://www.gnu.org/licenses/>.
18 %# @deftypefn {Function File} {[@var{}] =} odepkg_examples_dae (@var{})
19 %# Open the DAE examples menu and allow the user to select a demo that will be evaluated.
22 function [] = odepkg_examples_dae ()
24 vode = 1; while (vode > 0)
27 ['DAE examples menu:\n', ...
28 '==================\n', ...
30 ' (1) Solve the "Robertson problem" with solver "ode2r"\n', ...
31 ' (2) Solve another "Robertson implementation" with solver "ode5r"\n', ...
33 ' Note: There are further DAE examples available with the OdePkg\n', ...
34 ' testsuite functions.\n', ...
36 ' If you have another interesting DAE example that you would like\n', ...
37 ' to share then please modify this file, create a patch and send\n', ...
38 ' your patch with your added example to the OdePkg developer team.\n', ...
40 vode = input ('Please choose a number from above or press <Enter> to return: ');
41 clc; if (vode > 0 && vode < 3)
42 %# We can't use the function 'demo' directly here because it does
43 %# not allow to run other functions within a demo.
44 vexa = example (mfilename (), vode);
45 disp (vexa); eval (vexa);
46 input ('Press <Enter> to continue: ');
48 end %# while (vode > 0)
51 %! # Solve the "Robertson problem" with a Mass function that is given by
52 %! # a function handle.
54 %! function [vyd] = frobertson (vt, vy, varargin)
55 %! vyd(1,1) = -0.04 * vy(1) + 1e4 * vy(2) * vy(3);
56 %! vyd(2,1) = 0.04 * vy(1) - 1e4 * vy(2) * vy(3) - 3e7 * vy(2)^2;
57 %! vyd(3,1) = vy(1) + vy(2) + vy(3) - 1;
60 %! function [vmass] = fmass (vt, vy, varargin)
61 %! vmass = [1, 0, 0; 0, 1, 0; 0, 0, 0];
64 %! vopt = odeset ('Mass', @fmass, 'NormControl', 'on');
65 %! vsol = ode2r (@frobertson, [0, 1e5], [1, 0, 0], vopt);
66 %! plot (vsol.x, vsol.y);
69 %! # Solve the "Robertson problem" with a Mass function that is given by
70 %! # a constant mass matrix.
72 %! function [vyd] = frobertson (vt, vy, varargin)
73 %! vyd(1,1) = -0.04 * vy(1) + 1e4 * vy(2) * vy(3);
74 %! vyd(2,1) = 0.04 * vy(1) - 1e4 * vy(2) * vy(3) - 3e7 * vy(2)^2;
75 %! vyd(3,1) = vy(1) + vy(2) + vy(3) - 1;
78 %! vopt = odeset ('Mass', [1, 0, 0; 0, 1, 0; 0, 0, 0], ...
79 %! 'NormControl', 'on');
80 %! vsol = ode5r (@frobertson, [0, 1e5], [1, 0, 0], vopt);
81 %! plot (vsol.x, vsol.y);
83 %# Local Variables: ***