Mercurial > octave
annotate libinterp/corefcn/dassl.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc,
op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc,
op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc,
op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc,
op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc,
op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc,
op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc,
op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | c9788d7f6e65 |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
3 // Copyright (C) 1996-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2928 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
2928 | 28 #endif |
29 | |
30 #include <string> | |
31 | |
32 #include "DASSL.h" | |
33 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
34 #include "defun.h" |
2928 | 35 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
36 #include "errwarn.h" |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
37 #include "interpreter-private.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
38 #include "ovl.h" |
2968 | 39 #include "ov-fcn.h" |
5729 | 40 #include "ov-cell.h" |
2928 | 41 #include "pager.h" |
23473
55916f99b8b6
prefer feval over do_multi_index_op
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
42 #include "parse.h" |
3243 | 43 #include "unwind-prot.h" |
2928 | 44 #include "utils.h" |
45 #include "variables.h" | |
46 | |
3998 | 47 #include "DASSL-opts.cc" |
48 | |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30896
diff
changeset
|
49 OCTAVE_BEGIN_NAMESPACE(octave) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
50 |
2928 | 51 // Global pointer for user defined function required by dassl. |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
52 static octave_value dassl_fcn; |
2928 | 53 |
3991 | 54 // Global pointer for optional user defined jacobian function. |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
55 static octave_value dassl_jac; |
3991 | 56 |
4140 | 57 // Have we warned about imaginary values returned from user function? |
58 static bool warned_fcn_imaginary = false; | |
59 static bool warned_jac_imaginary = false; | |
60 | |
3243 | 61 // Is this a recursive call? |
62 static int call_depth = 0; | |
63 | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
64 static ColumnVector |
3849 | 65 dassl_user_function (const ColumnVector& x, const ColumnVector& xdot, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
66 double t, octave_idx_type& ires) |
2928 | 67 { |
68 ColumnVector retval; | |
69 | |
30723
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30564
diff
changeset
|
70 error_unless (x.numel () == xdot.numel ()); |
2928 | 71 |
72 octave_value_list args; | |
4628 | 73 |
2928 | 74 args(2) = t; |
4628 | 75 args(1) = xdot; |
76 args(0) = x; | |
2928 | 77 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
78 if (dassl_fcn.is_defined ()) |
2928 | 79 { |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
80 octave_value_list tmp; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
81 |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
82 try |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
83 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
84 tmp = feval (dassl_fcn, args, 1); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
85 } |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
86 catch (execution_exception& ee) |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
87 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28817
diff
changeset
|
88 err_user_supplied_eval (ee, "dassl"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
89 } |
2928 | 90 |
3849 | 91 int tlen = tmp.length (); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
92 if (tlen == 0 || ! tmp(0).is_defined ()) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
93 err_user_supplied_eval ("dassl"); |
4140 | 94 |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
95 if (! warned_fcn_imaginary && tmp(0).iscomplex ()) |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
96 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
97 warning ("dassl: ignoring imaginary part returned from user-supplied function"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
98 warned_fcn_imaginary = true; |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
99 } |
3849 | 100 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
101 retval = tmp(0).vector_value (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
102 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
103 if (tlen > 1) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
104 ires = tmp(1).int_value (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
105 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
106 if (retval.isempty ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
107 err_user_supplied_eval ("dassl"); |
2928 | 108 } |
109 | |
110 return retval; | |
111 } | |
112 | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
113 static Matrix |
3991 | 114 dassl_user_jacobian (const ColumnVector& x, const ColumnVector& xdot, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
115 double t, double cj) |
3991 | 116 { |
117 Matrix retval; | |
118 | |
30723
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30564
diff
changeset
|
119 error_unless (x.numel () == xdot.numel ()); |
3991 | 120 |
121 octave_value_list args; | |
122 | |
123 args(3) = cj; | |
124 args(2) = t; | |
4628 | 125 args(1) = xdot; |
126 args(0) = x; | |
3991 | 127 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
128 if (dassl_jac.is_defined ()) |
3991 | 129 { |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
130 octave_value_list tmp; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
131 |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
132 try |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
133 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
134 tmp = feval (dassl_jac, args, 1); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
135 } |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
136 catch (execution_exception& ee) |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
137 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28817
diff
changeset
|
138 err_user_supplied_eval (ee, "dassl"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
139 } |
3991 | 140 |
141 int tlen = tmp.length (); | |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
142 if (tlen == 0 || ! tmp(0).is_defined ()) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
143 err_user_supplied_eval ("dassl"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
144 |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
145 if (! warned_jac_imaginary && tmp(0).iscomplex ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
146 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
147 warning ("dassl: ignoring imaginary part returned from user-supplied jacobian function"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
148 warned_jac_imaginary = true; |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
149 } |
4140 | 150 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
151 retval = tmp(0).matrix_value (); |
3991 | 152 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
153 if (retval.isempty ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
154 err_user_supplied_eval ("dassl"); |
3991 | 155 } |
156 | |
157 return retval; | |
158 } | |
159 | |
23699
b29904962d2d
deprecate some global functions that access the symbol table
John W. Eaton <jwe@octave.org>
parents:
23581
diff
changeset
|
160 DEFMETHOD (dassl, interp, args, nargout, |
b29904962d2d
deprecate some global functions that access the symbol table
John W. Eaton <jwe@octave.org>
parents:
23581
diff
changeset
|
161 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
162 @deftypefn {} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} dassl (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit}) |
25106
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
163 Solve a set of differential-algebraic equations. |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
164 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
165 @code{dassl} solves the set of equations |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
166 @tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
167 $$ 0 = f (x, \dot{x}, t) $$ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
168 with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
169 $$ x(t_0) = x_0, \dot{x}(t_0) = \dot{x}_0 $$ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
170 @end tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
171 @ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
172 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
173 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
174 0 = f (x, xdot, t) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
175 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
176 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
177 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
178 with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
179 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
180 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
181 x(t_0) = x_0, xdot(t_0) = xdot_0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
182 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
183 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
184 @end ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
185 The solution is returned in the matrices @var{x} and @var{xdot}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
186 with each row in the result matrices corresponding to one of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
187 elements in the vector @var{t}. The first element of @var{t} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
188 should be @math{t_0} and correspond to the initial state of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
189 system @var{x_0} and its derivative @var{xdot_0}, so that the first |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
190 row of the output @var{x} is @var{x_0} and the first row |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
191 of the output @var{xdot} is @var{xdot_0}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
192 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
193 The first argument, @var{fcn}, is a string, inline, or function handle |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
194 that names the function @math{f} to call to compute the vector of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
195 residuals for the set of equations. It must have the form |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
196 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
197 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
198 @var{res} = f (@var{x}, @var{xdot}, @var{t}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
199 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
200 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
201 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
202 in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
203 scalar. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
204 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
205 If @var{fcn} is a two-element string array or a two-element cell array |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
206 of strings, inline functions, or function handles, the first element names |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
207 the function @math{f} described above, and the second element names a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
208 function to compute the modified Jacobian |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
209 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
210 @tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
211 $$ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
212 J = {\partial f \over \partial x} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
213 + c {\partial f \over \partial \dot{x}} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
214 $$ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
215 @end tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
216 @ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
217 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
218 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
219 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
220 df df |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
221 jac = -- + c ------ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
222 dx d xdot |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
223 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
224 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
225 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
226 @end ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
227 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
228 The modified Jacobian function must have the form |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
229 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
230 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
231 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
232 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
233 @var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
234 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
235 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
236 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
237 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
238 The second and third arguments to @code{dassl} specify the initial |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
239 condition of the states and their derivatives, and the fourth argument |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
240 specifies a vector of output times at which the solution is desired, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
241 including the time corresponding to the initial condition. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
242 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
243 The set of initial states and derivatives are not strictly required to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
244 be consistent. In practice, however, @sc{dassl} is not very good at |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
245 determining a consistent set for you, so it is best if you ensure that |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
246 the initial values result in the function evaluating to zero. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
247 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
248 The fifth argument is optional, and may be used to specify a set of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
249 times that the DAE solver should not integrate past. It is useful for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
250 avoiding difficulties with singularities and points where there is a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
251 discontinuity in the derivative. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
252 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
253 After a successful computation, the value of @var{istate} will be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
254 greater than zero (consistent with the Fortran version of @sc{dassl}). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
255 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
256 If the computation is not successful, the value of @var{istate} will be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
257 less than zero and @var{msg} will contain additional information. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
258 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
259 You can use the function @code{dassl_options} to set optional |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
260 parameters for @code{dassl}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
261 @seealso{daspk, dasrt, lsode} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
262 @end deftypefn */) |
2928 | 263 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
264 int nargin = args.length (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
265 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
266 if (nargin < 4 || nargin > 5) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
267 print_usage (); |
2928 | 268 |
4140 | 269 warned_fcn_imaginary = false; |
270 warned_jac_imaginary = false; | |
271 | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
272 octave_value_list retval (4); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
273 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
274 unwind_protect_var<int> restore_var (call_depth); |
3243 | 275 call_depth++; |
2928 | 276 |
3243 | 277 if (call_depth > 1) |
20957
9db35d2042be
maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
278 error ("dassl: invalid recursive call"); |
2928 | 279 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
280 std::string fcn_name, fname, jac_name, jname; |
23699
b29904962d2d
deprecate some global functions that access the symbol table
John W. Eaton <jwe@octave.org>
parents:
23581
diff
changeset
|
281 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
282 dassl_fcn = octave_value (); |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
283 dassl_jac = octave_value (); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
284 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
285 octave_value f_arg = args(0); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
286 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
287 std::list<std::string> fcn_param_names ({"x", "xdot", "t"}); |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
288 std::list<std::string> jac_param_names ({"x", "xdot", "t", "cj"}); |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
289 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23473
diff
changeset
|
290 if (f_arg.iscell ()) |
2928 | 291 { |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
292 Cell c = f_arg.cell_value (); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
293 if (c.numel () == 1) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
294 f_arg = c(0); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
295 else if (c.numel () == 2) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
296 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
297 dassl_fcn = get_function_handle (interp, c(0), fcn_param_names); |
3991 | 298 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
299 if (dassl_fcn.is_defined ()) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
300 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
301 dassl_jac = get_function_handle (interp, c(1), jac_param_names); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
302 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
303 if (dassl_jac.is_undefined ()) |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
304 dassl_fcn = octave_value (); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
305 } |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
306 } |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
307 else |
20957
9db35d2042be
maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
308 error ("dassl: incorrect number of elements in cell array"); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
309 } |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
310 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
311 if (dassl_fcn.is_undefined () && ! f_arg.iscell ()) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
312 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
313 if (f_arg.is_function_handle () || f_arg.is_inline_function ()) |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
314 dassl_fcn = f_arg; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
315 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
316 { |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
317 switch (f_arg.rows ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
318 { |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
319 case 1: |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
320 dassl_fcn = get_function_handle (interp, f_arg, fcn_param_names); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
321 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
322 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
323 case 2: |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
324 { |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
325 string_vector tmp = f_arg.string_vector_value (); |
3243 | 326 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
327 dassl_fcn = get_function_handle (interp, tmp(0), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
328 fcn_param_names); |
3991 | 329 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
330 if (dassl_fcn.is_defined ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
331 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
332 dassl_jac = get_function_handle (interp, tmp(1), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
333 jac_param_names); |
5729 | 334 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
335 if (dassl_jac.is_undefined ()) |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
336 dassl_fcn = octave_value (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
337 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
338 } |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
339 break; |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
340 |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
341 default: |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
342 error ("dassl: first arg should be a string or 2-element string array"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
343 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
344 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
345 } |
3243 | 346 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
347 if (dassl_fcn.is_undefined ()) |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
348 error ("dassl: FCN argument is not a valid function name or handle"); |
3243 | 349 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
350 ColumnVector state = args(1).xvector_value ("dassl: initial state X_0 must be a vector"); |
2928 | 351 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
352 ColumnVector deriv = args(2).xvector_value ("dassl: initial derivatives XDOT_0 must be a vector"); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
353 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
354 ColumnVector out_times = args(3).xvector_value ("dassl: output time variable T must be a vector"); |
2928 | 355 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
356 ColumnVector crit_times; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
357 int crit_times_set = 0; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
358 if (nargin > 4) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
359 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
360 crit_times = args(4).xvector_value ("dassl: list of critical times T_CRIT must be a vector"); |
2928 | 361 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
362 crit_times_set = 1; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
363 } |
3991 | 364 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
365 if (state.numel () != deriv.numel ()) |
20957
9db35d2042be
maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
366 error ("dassl: X and XDOT_0 must have the same size"); |
3991 | 367 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
368 double tzero = out_times (0); |
2928 | 369 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
370 DAEFunc fcn (dassl_user_function); |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
371 if (dassl_jac.is_defined ()) |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
372 fcn.set_jacobian_function (dassl_user_jacobian); |
3243 | 373 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
374 DASSL dae (state, deriv, tzero, fcn); |
2928 | 375 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
376 dae.set_options (dassl_opts); |
5729 | 377 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
378 Matrix output; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
379 Matrix deriv_output; |
3997 | 380 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
381 if (crit_times_set) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
382 output = dae.integrate (out_times, deriv_output, crit_times); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
383 else |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
384 output = dae.integrate (out_times, deriv_output); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
385 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
386 std::string msg = dae.error_message (); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
387 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
388 if (dae.integration_ok ()) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
389 { |
20892 | 390 retval(0) = output; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
391 retval(1) = deriv_output; |
2928 | 392 } |
3243 | 393 else |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
394 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
395 if (nargout < 3) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
396 error ("dassl: %s", msg.c_str ()); |
20892 | 397 |
398 retval(0) = Matrix (); | |
399 retval(1) = Matrix (); | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
400 } |
3243 | 401 |
20892 | 402 retval(2) = static_cast<double> (dae.integration_state ()); |
403 retval(3) = msg; | |
404 | |
2928 | 405 return retval; |
406 } | |
407 | |
408 /* | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
409 ## dassl-1.m |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
410 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
411 ## Test dassl() function |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
412 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
413 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
414 ## Comalco Research and Technology |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
415 ## 20 May 1998 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
416 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
417 ## Problem |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
418 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
419 ## y1' = -y2, y1(0) = 1 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
420 ## y2' = y1, y2(0) = 0 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
421 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
422 ## Solution |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
423 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
424 ## y1(t) = cos(t) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
425 ## y2(t) = sin(t) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
426 ## |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
427 %!function res = __f (x, xdot, t) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
428 %! res = [xdot(1)+x(2); xdot(2)-x(1)]; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
429 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
430 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
431 %!test |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
432 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
433 %! x0 = [1; 0]; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
434 %! xdot0 = [0; 1]; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
435 %! t = (0:1:10)'; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
436 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
437 %! tol = 100 * dassl_options ("relative tolerance"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
438 %! |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
439 %! [x, xdot] = dassl ("__f", x0, xdot0, t); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
440 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
441 %! y = [cos(t), sin(t)]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
442 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
443 %! assert (x, y, tol); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
444 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
445 ## dassl-2.m |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
446 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
447 ## Test dassl() function |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
448 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
449 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
450 ## Comalco Research and Technology |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
451 ## 20 May 1998 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
452 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
453 ## Based on SLATEC quick check for DASSL by Linda Petzold |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
454 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
455 ## Problem |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
456 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
457 ## x1' + 10*x1 = 0, x1(0) = 1 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
458 ## x1 + x2 = 1, x2(0) = 0 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
459 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
460 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
461 ## Solution |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
462 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
463 ## x1(t) = exp(-10*t) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
464 ## x2(t) = 1 - x(1) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
465 ## |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
466 %!function res = __f (x, xdot, t) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
467 %! res = [xdot(1)+10*x(1); x(1)+x(2)-1]; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
468 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
469 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
470 %!test |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
471 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
472 %! x0 = [1; 0]; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
473 %! xdot0 = [-10; 10]; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
474 %! t = (0:0.2:1)'; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
475 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
476 %! tol = 500 * dassl_options ("relative tolerance"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
477 %! |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
478 %! [x, xdot] = dassl ("__f", x0, xdot0, t); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
479 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
480 %! y = [exp(-10*t), 1-exp(-10*t)]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
481 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
482 %! assert (x, y, tol); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
483 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
484 %!test |
16780
781916090eb1
Restore dassl tolerance after running %! tests (bug #36137).
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
485 %! old_tol = dassl_options ("absolute tolerance"); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
486 %! dassl_options ("absolute tolerance", eps); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
487 %! assert (dassl_options ("absolute tolerance") == eps); |
16780
781916090eb1
Restore dassl tolerance after running %! tests (bug #36137).
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
488 %! ## Restore old value of tolerance |
781916090eb1
Restore dassl tolerance after running %! tests (bug #36137).
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
489 %! dassl_options ("absolute tolerance", old_tol); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
490 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
491 %!error dassl_options ("foo", 1, 2) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
492 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
493 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30896
diff
changeset
|
494 OCTAVE_END_NAMESPACE(octave) |