Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

Technical Solutions

Why do I receive a an error when specifying two event functions to the ODE solvers within MATLAB 7.0 (R14)?


Date Last Modified: 06 Nov 2007
Solution ID:   1-QAZDS
Product:   MATLABĀ®
Reported in Release:   R14
Fixed in Release:   R14SP2
Platform:   All Platforms
Operating System:   All OS
 

Subject:

Why do I receive a an error when specifying two event functions to the ODE solvers within MATLAB 7.0 (R14)?

Problem Description:

To reproduce this error, save the following code within an M-file, and then execute.

function mysoup
options = odeset('Stats', 'on', 'Events', @ex19ach1e);
tspan = [0 2];
y0 = [0 ; 0];
yspan=(1:9)'/10;
[t,y,te,ye,ie] = ode45(@ex26ch2f,tspan, y0, options,yspan);
disp('te = '), disp(te)

function yprime = ex26ch2f(t,y,yspan)
yprime = [y(2) ; 1/2];

function [value, isterminal, direction] = ex19ach1e(t,y,yspan)
isterminal = zeros(size(yspan)); direction = zeros(size(yspan));
value = y(1) - yspan;

I receive the following error message;

??? Error using ==> horzcat
All matrices on a row in the bracketed expression must have the
same number of rows.

Solution:

This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:

This has been verified as a bug within the ODEZERO function, which is called by the ODE solvers within MATLAB 7.0 (R14), in the way it handles multiple event functions.

To work around this issue, download a revised version of the M-files odezero.m and dde23.m. Note that due to file dependencies you must update both files. Here are the required steps:

1. Quit MATLAB

2. Rename the following M-files:
$MATLAB\toolbox\matlab\funfun\dde23.m
$MATLAB\toolbox\matlab\funfun\private\odezero.m

(where $MATLAB is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB command prompt.)

Rename the files to odezero.m.old and dde23.m.old.

3. Download the following file from our Web site:

http://www.mathworks.com/support/solutions/files/s1-QAZDS/dde23.m
http://www.mathworks.com/support/solutions/files/s1-QAZDS/odezero.m

Place the new M-files in the same directories mentioned in step 2.

4. Restart MATLAB

5. After restarting MATLAB, issue the following command at the MATLAB prompt:

rehash toolboxcache

  Provide feedback to help us improve this solution!
Contact support
E-mail this page
Print this page