/tags/cvs_final/octave-forge/main/odepkg/inst/odeprint.m

# · MATLAB · 68 lines · 10 code · 9 blank · 49 comment · 3 complexity · b3592f597a459ee2bc9c1c8afde28d7e MD5 · raw file

  1. %# Copyright (C) 2006, Thomas Treichl <treichl@users.sourceforge.net>
  2. %# OdePkg - Package for solving ordinary differential equations with octave
  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, write to the Free Software
  16. %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. %# -*- texinfo -*-
  18. %# @deftypefn {Function} {@var{[ret]} =} odeprint (@var{t, y, flag})
  19. %# 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 output. This function is an odepkg plotter function that can be set with @command{odeset}, therefore this function should never be directly called by the user. No error handling has been implemented in this function to achieve the highest processing speed.
  20. %#
  21. %# Run
  22. %# @example
  23. %# demo odeprint
  24. %# @end example
  25. %# to see an example.
  26. %# @end deftypefn
  27. %#
  28. %# @seealso{odepkg}
  29. %# As in the definitions of initial value problems as functions and if
  30. %# somebody uses event functions all input and output vectors must be
  31. %# column vectors by now.
  32. function [varargout] = odeprint (vt, vy, vflag, varargin)
  33. %# No input argument check is done for a higher processing speed
  34. %# vt and vy are always column vectors, see also function odeplot,
  35. %# odephas2 and odephas3 for another implementation. vflag either
  36. %# is "init", [] or "done".
  37. if (strcmp (vflag, 'init') == true)
  38. fprintf (1, '%f%s\n', vt (1,1), sprintf (' %f', vy) );
  39. fflush (1);
  40. elseif (isempty (vflag) == true) %# Return varargout{1}
  41. fprintf (1, '%f%s\n', vt (1,1), sprintf (' %f', vy) );
  42. fflush (1);
  43. varargout{1} = true;
  44. %# Do not stop the integration algorithm
  45. %# if varargout{1} = false; stop the integration algorithm
  46. elseif (strcmp (vflag, 'done') == true)
  47. %# Cleanup could be done, but nothing to do in this function
  48. end
  49. %!demo
  50. %!
  51. %! A = odeset ('OutputFcn', @odeprint);
  52. %! [vx, vy] = ode78 (@odepkg_equations_secondorderlag, [0 1.5], [0 0], A);
  53. %!
  54. %! % ---------------------------------------------------------------------
  55. %! % The output of the integration is ploted with odeprint because the
  56. %! % OuputFcn property has been set with odeset.
  57. %# Local Variables: ***
  58. %# mode: octave ***
  59. %# End: ***