Why do I receive an error about a SWITCH expression when using ODE15S within MATLAB?

조회 수: 4 (최근 30일)
When solving a differential-algebraic system (DAE) via the command:
options = odeset('Mass', rand(3));
[t,z] = ode15s('odefun', TSPAN, X0, options);
where odefun is the derivative function, I receive the following error:
??? SWITCH expression must be a scalar or string constant.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
This error is a result of using conflicting syntaxes from different versions of MATLAB. In this example, the derivative function is specified as a string, while the "Mass" property is specified as a constant mass matrix.
The abilities to set the "Mass" property of the option argument to a constant mass matrix and to use function handles for the derivative function were added in MATLAB 6.0 (R12).
In older versions, the derivative function was called using a string, and the acceptable settings for the "Mass" property were "none", "M", "M(t)", and "M(t, y)". The value for the mass matrix had to be returned by the derivative function called using the flag "mass" even for constant mass matrices.
In MATLAB 6.0 (R12) and later versions, you can specify a constant mass matrix as the value for the "Mass" property in the options argument. Because this new functionality is only available when using the new syntax, you must then call the ODE functions using a function handle rather than a string.
Therefore, the statement:
[t,z] = ode15s('odefun', TSPAN, X0, options);
should be changed to:
[t,z] = ode15s(@odefun, TSPAN, X0, options);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by