comparison scripts/ode/odeplot.m @ 31263:449ed6f427cb

ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063) * scripts/ode/ode23.m: Remove disabling of Refine option with struct output. Modify solution struct to output two sets of solution variables: output_t, output_x and ode_t and ode_x, and transpose struct output variables for improved Matlab compatibility. Update BISTs and perform minor code formatting. * scripts/ode/ode23s.m: Make same changes as ode23.m. * scripts/ode/ode45.m: Make same changes as ode23.m. Remove comment indicating that Refine is not implemented. * scripts/ode/private/integrate_adaptive.m: Update internal handling of variables t and x, separating them into ode_t & ode_x for internal integration and output_t & output_x for function output or calls to OutputFcn. Replace prior attempt at Refine option with new implementation. Specify time output or Refine != 0 are both interpolated from internal variables (ode_t, ode_x) for output of non-struct variables and/or for use with OutputFcn. Improve event handling when multiple Events (including at least one terminal Event) are detected in a single simulation step so that all Events up to and including the first terminal one are reported, and final data point is set to that of terminal Event. Send multiple data points in a single call to OutputFcn if they are all interpolated from a single integration step. Remove warning for termination when term signal is received from Events or OutputFcn. Return both internal variables (ode_t, ode_x) and interpolated variables (output_t, output_x) to allow calling function to correctly return either struct or separate variables. * scripts/ode/private/ode_event_handler.m: Sort multiple Events in ascending time order when they are encountered in one integration step. Remove any events after the time of a terminal Event. * scripts/ode/odeset.m: Update docstring to remove indication that Refine is not implemented * scripts/ode/odeplot.m: Update docstring to indicate that input t can be a scalar or vector. Add file test. * etc/NEWS.8.md: Add descriptions of changes under General improvements and Matlab compatibility.
author Ken Marek <marek_ka@mercer.edu>
date Wed, 05 Oct 2022 16:53:01 -0400
parents 796f54d4ddbf
children c332a2f2959f
comparison
equal deleted inserted replaced
31262:b8f4ec18e728 31263:449ed6f427cb
38 ## The input @var{t} must be a column vector of length 2 with the first and 38 ## The input @var{t} must be a column vector of length 2 with the first and
39 ## last time step (@code{[@var{tfirst} @var{tlast}]}. The input @var{y} 39 ## last time step (@code{[@var{tfirst} @var{tlast}]}. The input @var{y}
40 ## contains the initial conditions for the ode problem (@var{y0}). 40 ## contains the initial conditions for the ode problem (@var{y0}).
41 ## 41 ##
42 ## @item @qcode{""} 42 ## @item @qcode{""}
43 ## The input @var{t} must be a scalar double specifying the time for which 43 ## The input @var{t} must be a scalar double or vector specifying the time(s)
44 ## the solution in input @var{y} was calculated. 44 ## for which the solution in input @var{y} was calculated.
45 ## 45 ##
46 ## @item @qcode{"done"} 46 ## @item @qcode{"done"}
47 ## The inputs should be empty, but are ignored if they are present. 47 ## The inputs should be empty, but are ignored if they are present.
48 ## @end table 48 ## @end table
49 ## 49 ##
118 %! ## Solve an anonymous implementation of the Van der Pol equation 118 %! ## Solve an anonymous implementation of the Van der Pol equation
119 %! ## and display the results while solving 119 %! ## and display the results while solving
120 %! fvdp = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)]; 120 %! fvdp = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)];
121 %! opt = odeset ("OutputFcn", @odeplot, "RelTol", 1e-6); 121 %! opt = odeset ("OutputFcn", @odeplot, "RelTol", 1e-6);
122 %! sol = ode45 (fvdp, [0 20], [2 0], opt); 122 %! sol = ode45 (fvdp, [0 20], [2 0], opt);
123
124 ## FIXME: convert to demo or a visible=off test with failable assert/error
125 ## statemments
126 ## Test that the function works for expected ode OutputFcn calls
127 ## %!test
128 ## %! t = linspace(0,2,10);
129 ## %! y = [0.2*t; -0.1*t.^2-1; sin(t)];
130 ## %! odeplot ([0 2], y(:,1), "init");
131 ## %! odeplot (t(2), y(:,2), []);
132 ## %! odeplot (t(3:end), y(:, 3:end), []);
133 ## %! odeplot ([], [], "done");
134 ## %! close all