]> Creatis software - CreaPhase.git/blob - octave_packages/odepkg-0.8.2/odepkg_examples_ide.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / odepkg-0.8.2 / odepkg_examples_ide.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_ide (@var{})
19 %# Open the IDE examples menu and allow the user to select a demo that will be evaluated.
20 %# @end deftypefn
21
22 function [] = odepkg_examples_ide ()
23
24   vode = 1; while (vode > 0)
25     clc;
26     fprintf (1, ...
27       ['IDE examples menu:\n', ...
28        '==================\n', ...
29        '\n', ...
30        '   (1) Solve the "Robertson problem" with solver "odebdi"\n', ...
31        '   (2) Solve another "Robertson implementation" with solver "odekdi"\n', ...
32        '   (3) Solve a stiff "Van der Pol" implementation with solver "odebdi"\n', ...
33        '   (4) Solve a stiff "Van der Pol" implementation with solver "odekdi"\n', ...
34        '\n', ...
35        '   Note: There are further IDE examples available with the OdePkg\n', ...
36        '         testsuite functions.\n', ...
37        '\n', ...
38        '   If you have another interesting IDE example that you would like\n', ...
39        '   to share then please modify this file, create a patch and send\n', ...
40        '   your patch to the OdePkg developer team.\n', ...
41        '\n' ]);
42     vode = input ('Please choose a number from above or press <Enter> to return: ');
43     clc; if (vode > 0 && vode < 5)
44       %# We can't use the function 'demo' directly here because it does
45       %# not allow to run other functions within a demo.
46       vexa = example (mfilename (), vode);
47       disp (vexa); eval (vexa);
48       input ('Press <Enter> to continue: ');
49     end %# if (vode > 0)
50   end %# while (vode > 0)
51
52 %!demo
53 %! # Solve the "Robertson problem" that is given as a function handle
54 %! # to an implicite differential equation implementation.
55 %!
56 %! function [vres] = firobertson (vt, vy, vyd, varargin)
57 %!   vres(1,1) = -0.04*vy(1) + 1e4*vy(2)*vy(3) - vyd(1);
58 %!   vres(2,1) =  0.04*vy(1) - 1e4*vy(2)*vy(3) - 3e7*vy(2)^2-vyd(2);
59 %!   vres(3,1) =  vy(1) + vy(2) + vy(3) - 1;
60 %! endfunction
61 %!
62 %! vopt = odeset ("NormControl", "on");
63 %! vsol = odebdi (@firobertson, [0, 1e5], [1, 0, 0], [-4e-2, 4e-2, 0], vopt);
64 %! plot (vsol.x, vsol.y);
65
66 %!demo
67 %! # Solve the "Robertson problem" that is given as a function handle
68 %! # to an implicite differential equation implementation.
69 %!
70 %! function [vres] = firobertson (vt, vy, vyd, varargin)
71 %!   vres(1,1) = -0.04*vy(1) + 1e4*vy(2)*vy(3) - vyd(1);
72 %!   vres(2,1) =  0.04*vy(1) - 1e4*vy(2)*vy(3) - 3e7*vy(2)^2-vyd(2);
73 %!   vres(3,1) =  vy(1) + vy(2) + vy(3) - 1;
74 %! endfunction
75 %!
76 %! vopt = odeset ("NormControl", "on");
77 %! vsol = odekdi (@firobertson, [0, 1e5], [1, 0, 0], [-4e-2, 4e-2, 0], vopt);
78 %! plot (vsol.x, vsol.y);
79
80 %!demo
81 %! # Solve the "Van der Pol" problem that is given as a function
82 %! # handle to an implicite differential equation implementation.
83 %!
84 %! function [vres] = fvanderpol (vt, vy, vyd, varargin)
85 %!   mu = varargin{1};
86 %!   vres = [vy(2) - vyd(1); 
87 %!           mu * (1 - vy(1)^2) * vy(2) - vy(1) - vyd(2)];
88 %! endfunction
89 %!
90 %! vopt = odeset ("NormControl", "on", "RelTol", 1e-8, "MaxStep", 1e-2);
91 %! vsol = odebdi (@fvanderpol, [0, 20], [2; 0], [0; -2], vopt, 10);
92 %! plot (vsol.x, vsol.y);
93
94 %!demo
95 %! # Solve the "Van der Pol" problem that is given as a function
96 %! # handle to an implicite differential equation implementation.
97 %!
98 %! function [vres] = fvanderpol (vt, vy, vyd, varargin)
99 %!   mu = varargin{1};
100 %!   vres = [vy(2) - vyd(1); 
101 %!           mu * (1 - vy(1)^2) * vy(2) - vy(1) - vyd(2)];
102 %! endfunction
103 %!
104 %! vsol = odekdi (@fvanderpol, [0, 1000], [2; 0], [0; -2], 500);
105 %! plot (vsol.x, vsol.y);
106
107 %# Local Variables: ***
108 %# mode: octave ***
109 %# End: ***