[452189]: inst / odeprint.m  Maximize  Restore  History

Download this file

67 lines (57 with data), 3.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
%# Copyright (C) 2006, Thomas Treichl <treichl@users.sourceforge.net>
%# OdePkg - Package for solving ordinary differential equations with octave
%#
%# This program is free software; you can redistribute it and/or modify
%# it under the terms of the GNU General Public License as published by
%# the Free Software Foundation; either version 2 of the License, or
%# (at your option) any later version.
%#
%# This program is distributed in the hope that it will be useful,
%# but WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%# GNU General Public License for more details.
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
%# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%# -*- texinfo -*-
%# @deftypefn {Function} {@var{[ret]} =} odeprint (@var{t, y, flag})
%# Displays the results of the differential equations in the octave window while solving. The first column shows the actual time stamp, the following columns show the values of the solvers for each time stamp. The return value @var{ret} depends on the input value @var{flag}. If @var{flag} is the string "init" then nothing is returned, else if @var{flag} is empty then true (resp. value 1) is returned to tell the calling solver function to continue, else if @var{flag} is the string "done" then again nothing will be returned. The input arguments @var{t} and @var{y} are the actual time stamp and the solver outputs as row vectors. There is no error handling implemented in this function to achieve the highest performance.
%#
%# Run
%# @example
%# demo odeprint
%# @end example
%# to see an example.
%# @end deftypefn
%#
%# @seealso{odepkg}
%# Maintainer: Thomas Treichl
%# Created: 20060809
%# ChangeLog:
function [varargout] = odeprint (vt, vy, vflag, varargin)
%# No input argument check is done for a higher processing speed
%# vt and vy are always column vectors, see also function odeplot,
%# odephas2 and odephas3 for another implementation. vflag either
%# is "init", [] or "done".
if (strcmp (vflag, 'init') == true)
fprintf (1, '%f%s\n', vt (1,1), sprintf (' %f', vy) );
elseif (isempty (vflag) == true) %# Return varargout{1}
fprintf (1, '%f%s\n', vt (1,1), sprintf (' %f', vy) );
varargout{1} = true;
%# Do not stop the integration algorithm
%# if varargout{1} = false; stop the integration algorithm
elseif (strcmp (vflag, 'done') == true)
%# Cleanup could be done, but nothing to do in this function
end
%!demo
%!
%! A = odeset ('OutputFcn', @odeprint);
%! [vx, vy] = ode78 (@odepkg_equations_secondorderlag, [0 1.5], [0 0], A);
%!
%! % ---------------------------------------------------------------------
%! % The output of the integration is ploted with odeprint because the
%! % OuputFcn property has been set with odeset.
%# Local Variables: ***
%# mode: octave ***
%# End: ***