26 #if defined (HAVE_CONFIG_H)
59 static bool warned_fcn_imaginary =
false;
60 static bool warned_jac_imaginary =
false;
61 static bool warned_cf_imaginary =
false;
64 static int call_depth = 0;
88 tmp = interp.
feval (dasrt_fcn, args, 1);
95 if (tmp.
empty () || ! tmp(0).is_defined ())
98 if (! warned_fcn_imaginary && tmp(0).iscomplex ())
100 warning (
"dasrt: ignoring imaginary part returned from user-supplied function");
101 warned_fcn_imaginary =
true;
104 retval = tmp(0).vector_value ();
131 tmp = interp.
feval (dasrt_cf, args, 1);
138 if (tmp.
empty () || ! tmp(0).is_defined ())
141 if (! warned_cf_imaginary && tmp(0).iscomplex ())
143 warning (
"dasrt: ignoring imaginary part returned from user-supplied constraint function");
144 warned_cf_imaginary =
true;
147 retval = tmp(0).vector_value ();
179 tmp = interp.
feval (dasrt_jac, args, 1);
187 if (tlen == 0 || ! tmp(0).is_defined ())
190 if (! warned_jac_imaginary && tmp(0).iscomplex ())
192 warning (
"dasrt: ignoring imaginary part returned from user-supplied jacobian function");
193 warned_jac_imaginary =
true;
196 retval = tmp(0).matrix_value ();
348 int nargin = args.
length ();
350 if (nargin < 4 || nargin > 6)
353 warned_fcn_imaginary =
false;
354 warned_jac_imaginary =
false;
355 warned_cf_imaginary =
false;
363 error (
"dasrt: invalid recursive call");
366 std::string fcn_name, fname, jac_name, jname;
378 std::list<std::string> fcn_param_names ({
"x",
"xdot",
"t"});
379 std::list<std::string> jac_param_names ({
"x",
"xdot",
"t",
"cj"});
386 else if (c.
numel () == 2)
399 error (
"dasrt: incorrect number of elements in cell array");
408 switch (f_arg.
rows ())
433 error (
"dasrt: first arg should be a string or 2-element string array");
439 error (
"dasrt: FCN argument is not a valid function name or handle");
445 if (args(1).isempty () && args(1).is_double_type ())
454 if (args(1).is_function_handle () || args(1).is_inline_function ()
455 || args(1).is_string ())
457 std::list<std::string> cf_param_names ({
"x",
"t"});
470 if (argp + 3 > nargin)
473 ColumnVector state = args(argp++).xvector_value (
"dasrt: initial state X_0 must be a vector");
475 ColumnVector stateprime = args(argp++).xvector_value (
"dasrt: initial derivatives XDOT_0 must be a vector");
477 ColumnVector out_times = args(argp++).xvector_value (
"dasrt: output time variable T must be a vector");
479 double tzero = out_times (0);
483 bool crit_times_set =
false;
487 crit_times = args(argp).xvector_value (
"dasrt: list of critical times T_CRIT must be a vector");
490 crit_times_set =
true;
498 DASRT dae =
DASRT (state, stateprime, tzero, fcn);
503 output = dae.
integrate (out_times, crit_times);
511 retval(0) = output.
state ();
512 retval(1) = output.
deriv ();
513 retval(2) = output.
times ();
518 error (
"dasrt: %s", msg.c_str ());
531 OCTAVE_END_NAMESPACE(
octave)
bool isempty() const
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
DAEFunc & set_jacobian_function(DAEJacFunc j)
DAERTFunc & set_constraint_function(DAERTConstrFunc cf)
void set_options(const DASRT_options &opt)
ColumnVector times() const
DASRT_result integrate(const ColumnVector &tout)
std::string error_message() const
octave_idx_type integration_state() const
bool integration_ok() const
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
octave_idx_type length() const
bool is_function_handle() const
bool is_undefined() const
bool is_inline_function() const
octave_idx_type rows() const
string_vector string_vector_value(bool pad=false) const
DEFMETHOD(dasrt, interp, args, nargout, doc:)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value dasrt_fcn
void warning(const char *fmt,...)
void() error(const char *fmt,...)
#define error_unless(cond)
void err_user_supplied_eval(const char *name)
interpreter & __get_interpreter__()
octave_value get_function_handle(interpreter &interp, const octave_value &arg, const std::string ¶meter_name)
F77_RET_T const F77_DBLE * x
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))