From bug-request at octave dot org Tue Nov 29 23:56:34 2005 Subject: lsode crashes with integration method stiff and maximum order != -1 From: "John W. Eaton" To: Gero Putzar Cc: bug at octave dot org Date: Wed, 30 Nov 2005 00:56:22 -0500 On 17-Nov-2005, Gero Putzar wrote: | To: bug at octave dot org | Cc: gero | Subject: lsode crashes with integration method stiff and maximum order != -1 | | Bug report for Octave 2.1.69 configured for i386-pc-linux-gnu | | Description: | ----------- | | octave stops with a segmentation fault, when integrating an ODE with the | method 'stiff' and the lsode_option maximum order set to a value between | 1 and 5. | | Repeat-By: | --------- | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %% dot x = v | %% dot v = -F(a-x) - v - k(x-v0*t) | %% F(x) = 0.5*(x^(-13) - x^(-7)) | | function xdot = f(x,t) | xdot = zeros(2,1); | F = 0.5*((2.0 - x(1))^(-13) - (2.0 - x(1))^(-7)); | xdot(1) = x(2); | xdot(2) = -F - x(2) - (x(1)-t); | endfunction | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | | x0 = [-1.0 ; 1]; | tvec = 0:0.2:20; | | lsode_options('integration method', 'stiff'); | lsode_options('relative tolerance', 1E-3); | lsode_options('maximum order', 5); | | ignore_function_time_stamp = 'all'; | t = cputime (); | [x, istate, msg] = lsode ('f', x0, tvec); | disp(['Finished. cputime:', num2str(cputime () - t)]); | ignore_function_time_stamp = 'system'; | | if (istate != 2) | error( msg ); | else | plot(tvec, x); | pause; | endif Please try the following patch. Thanks, jwe liboctave/ChangeLog: 2005-11-30 John W. Eaton * LSODE.cc (LSODE::do_integrate (double)): Resize iwork and rwork before setting any values in either array. Index: liboctave/LSODE.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/LSODE.cc,v retrieving revision 1.56.2.1 diff -u -r1.56.2.1 LSODE.cc --- liboctave/LSODE.cc 26 Apr 2005 19:43:54 -0000 1.56.2.1 +++ liboctave/LSODE.cc 30 Nov 2005 05:48:07 -0000 at @ -153,6 +153,16 @@ maxord = maximum_order (); + iwork.resize (liw); + + for (int i = 4; i < 9; i++) + iwork(i) = 0; + + rwork.resize (lrw); + + for (int i = 4; i < 9; i++) + rwork(i) = 0; + if (maxord >= 0) { if (maxord > 0 && maxord <= max_maxord) at @ -169,16 +179,6 @@ } } - iwork.resize (liw); - - for (int i = 4; i < 9; i++) - iwork(i) = 0; - - rwork.resize (lrw); - - for (int i = 4; i < 9; i++) - rwork(i) = 0; - if (stop_time_set) { itask = 4; ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------