]> Creatis software - CreaPhase.git/blob - octave_packages/odepkg-0.8.2/odepkg_examples_dae.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / odepkg-0.8.2 / odepkg_examples_dae.m
1 %# Copyright (C) 2008-2012, Thomas Treichl <treichl@users.sourceforge.net>
2 %# OdePkg - A package for solving ordinary differential equations and more
3 %#
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.
8 %#
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.
13 %#
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/>.
16
17 %# -*- texinfo -*-
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.
20 %# @end deftypefn
21
22 function [] = odepkg_examples_dae ()
23
24   vode = 1; while (vode > 0)
25     clc;
26     fprintf (1, ...
27       ['DAE examples menu:\n', ...
28        '==================\n', ...
29        '\n', ...
30        '   (1) Solve the "Robertson problem" with solver "ode2r"\n', ...
31        '   (2) Solve another "Robertson implementation" with solver "ode5r"\n', ...
32        '\n', ...
33        '   Note: There are further DAE examples available with the OdePkg\n', ...
34        '         testsuite functions.\n', ...
35        '\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', ...
39        '\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: ');
47     end %# if (vode > 0)
48   end %# while (vode > 0)
49
50 %!demo
51 %! # Solve the "Robertson problem" with a Mass function that is given by
52 %! # a function handle.
53 %!
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;
58 %! endfunction
59 %!
60 %! function [vmass] = fmass (vt, vy, varargin)
61 %!   vmass =  [1, 0, 0; 0, 1, 0; 0, 0, 0];
62 %! endfunction
63 %!
64 %! vopt = odeset ('Mass', @fmass, 'NormControl', 'on');
65 %! vsol = ode2r (@frobertson, [0, 1e5], [1, 0, 0], vopt);
66 %! plot (vsol.x, vsol.y);
67
68 %!demo
69 %! # Solve the "Robertson problem" with a Mass function that is given by
70 %! # a constant mass matrix.
71 %!
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;
76 %! endfunction
77 %!
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);
82
83 %# Local Variables: ***
84 %# mode: octave ***
85 %# End: ***