├── .codespell-ignorelines ├── .codespell-ignorewords ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .mailmap ├── CONTRIBUTORS ├── COPYING ├── DESCRIPTION ├── HOWTO-release.md ├── INDEX ├── Makefile ├── NEWS ├── README.matlab.md ├── README.md ├── TODO.md ├── icon.png ├── inst ├── .oct-config ├── @double │ ├── adjoint.m │ ├── bernoulli.m │ ├── chebyshevT.m │ ├── chebyshevU.m │ ├── coshint.m │ ├── cosint.m │ ├── dilog.m │ ├── euler.m │ ├── fresnelc.m │ ├── fresnels.m │ ├── harmonic.m │ ├── logint.m │ ├── pochhammer.m │ ├── polylog.m │ ├── sinhint.m │ ├── sinint.m │ └── zeta.m ├── @logical │ └── isAlways.m ├── @sym │ ├── abs.m │ ├── acos.m │ ├── acosd.m │ ├── acosh.m │ ├── acot.m │ ├── acoth.m │ ├── acsc.m │ ├── acsch.m │ ├── adjoint.m │ ├── airy.m │ ├── all.m │ ├── and.m │ ├── angle.m │ ├── any.m │ ├── arg.m │ ├── argnames.m │ ├── asec.m │ ├── asech.m │ ├── asin.m │ ├── asind.m │ ├── asinh.m │ ├── assume.m │ ├── assumeAlso.m │ ├── atan.m │ ├── atan2.m │ ├── atand.m │ ├── atanh.m │ ├── bernoulli.m │ ├── besselh.m │ ├── besseli.m │ ├── besselj.m │ ├── besseljn.m │ ├── besselk.m │ ├── bessely.m │ ├── besselyn.m │ ├── beta.m │ ├── cart2pol.m │ ├── cat.m │ ├── cbrt.m │ ├── ccode.m │ ├── ceil.m │ ├── char.m │ ├── charpoly.m │ ├── chebyshevT.m │ ├── chebyshevU.m │ ├── children.m │ ├── chol.m │ ├── coeffs.m │ ├── collect.m │ ├── colon.m │ ├── columns.m │ ├── cond.m │ ├── conj.m │ ├── cos.m │ ├── cosd.m │ ├── cosh.m │ ├── coshint.m │ ├── cosint.m │ ├── cot.m │ ├── coth.m │ ├── cross.m │ ├── csc.m │ ├── csch.m │ ├── ctranspose.m │ ├── cumprod.m │ ├── cumsum.m │ ├── curl.m │ ├── dawson.m │ ├── degree.m │ ├── det.m │ ├── diag.m │ ├── diff.m │ ├── dilog.m │ ├── dirac.m │ ├── disp.m │ ├── display.m │ ├── divergence.m │ ├── divisors.m │ ├── dot.m │ ├── double.m │ ├── dsolve.m │ ├── ei.m │ ├── eig.m │ ├── ellipke.m │ ├── ellipticCE.m │ ├── ellipticCK.m │ ├── ellipticCPi.m │ ├── ellipticE.m │ ├── ellipticF.m │ ├── ellipticK.m │ ├── ellipticPi.m │ ├── end.m │ ├── eq.m │ ├── equationsToMatrix.m │ ├── erf.m │ ├── erfc.m │ ├── erfcinv.m │ ├── erfi.m │ ├── erfinv.m │ ├── euler.m │ ├── eval.m │ ├── exp.m │ ├── expand.m │ ├── expint.m │ ├── expm.m │ ├── eye.m │ ├── ezcontour.m │ ├── ezmesh.m │ ├── ezplot.m │ ├── ezplot3.m │ ├── ezsurf.m │ ├── factor.m │ ├── factorial.m │ ├── find.m │ ├── findsym.m │ ├── fix.m │ ├── fliplr.m │ ├── flipud.m │ ├── floor.m │ ├── formula.m │ ├── fortran.m │ ├── fourier.m │ ├── fplot.m │ ├── frac.m │ ├── fresnelc.m │ ├── fresnels.m │ ├── function_handle.m │ ├── gamma.m │ ├── gammainc.m │ ├── gammaln.m │ ├── ge.m │ ├── gradient.m │ ├── gt.m │ ├── harmonic.m │ ├── has.m │ ├── heaviside.m │ ├── hessian.m │ ├── hilb.m │ ├── horner.m │ ├── horzcat.m │ ├── hypergeom.m │ ├── hypot.m │ ├── ifourier.m │ ├── igamma.m │ ├── ilaplace.m │ ├── imag.m │ ├── int.m │ ├── intersect.m │ ├── interval.m │ ├── inv.m │ ├── invhilb.m │ ├── ipermute.m │ ├── isAlways.m │ ├── isNone.m │ ├── isallconstant.m │ ├── iscolumn.m │ ├── isconstant.m │ ├── isempty.m │ ├── isequal.m │ ├── isequaln.m │ ├── isfinite.m │ ├── isinf.m │ ├── ismatrix.m │ ├── ismember.m │ ├── isna.m │ ├── isnan.m │ ├── isprime.m │ ├── isrow.m │ ├── isscalar.m │ ├── isvector.m │ ├── jacobian.m │ ├── jordan.m │ ├── kron.m │ ├── kroneckerDelta.m │ ├── laguerreL.m │ ├── lambertw.m │ ├── laplace.m │ ├── laplacian.m │ ├── latex.m │ ├── ldivide.m │ ├── le.m │ ├── length.m │ ├── lgamma.m │ ├── lhs.m │ ├── limit.m │ ├── linspace.m │ ├── log.m │ ├── log10.m │ ├── log2.m │ ├── logical.m │ ├── logint.m │ ├── logspace.m │ ├── lt.m │ ├── lu.m │ ├── matlabFunction.m │ ├── max.m │ ├── min.m │ ├── minus.m │ ├── mldivide.m │ ├── mod.m │ ├── mpower.m │ ├── mrdivide.m │ ├── mtimes.m │ ├── nchoosek.m │ ├── ne.m │ ├── nextprime.m │ ├── nnz.m │ ├── norm.m │ ├── not.m │ ├── null.m │ ├── numden.m │ ├── numel.m │ ├── ones.m │ ├── or.m │ ├── orth.m │ ├── partfrac.m │ ├── permute.m │ ├── piecewise.m │ ├── pinv.m │ ├── plus.m │ ├── pochhammer.m │ ├── pol2cart.m │ ├── polylog.m │ ├── potential.m │ ├── power.m │ ├── pretty.m │ ├── prevprime.m │ ├── private │ │ ├── assert_same_shape.m │ │ ├── cell2nosyms.m │ │ ├── check_assumptions.m │ │ ├── codegen.m │ │ ├── detect_special_str.m │ │ ├── do_highbyte_escapes.m │ │ ├── double_to_sym_exact.m │ │ ├── double_to_sym_heuristic.m │ │ ├── elementwise_op.m │ │ ├── ineq_helper.m │ │ ├── is_same_shape.m │ │ ├── is_valid_index.m │ │ ├── make_sym_matrix.m │ │ ├── mat_access.m │ │ ├── mat_rccross_access.m │ │ ├── mat_rclist_access.m │ │ ├── mat_rclist_asgn.m │ │ ├── mat_replace.m │ │ ├── numeric_array_to_sym.m │ │ └── uniop_bool_helper.m │ ├── private_disp_name.m │ ├── prod.m │ ├── psi.m │ ├── qr.m │ ├── rank.m │ ├── rdivide.m │ ├── real.m │ ├── repmat.m │ ├── reshape.m │ ├── resize.m │ ├── rewrite.m │ ├── rhs.m │ ├── round.m │ ├── rows.m │ ├── rref.m │ ├── sec.m │ ├── sech.m │ ├── setdiff.m │ ├── setxor.m │ ├── sign.m │ ├── signIm.m │ ├── simplify.m │ ├── sin.m │ ├── sinc.m │ ├── sind.m │ ├── sinh.m │ ├── sinhint.m │ ├── sinint.m │ ├── size.m │ ├── solve.m │ ├── sort.m │ ├── sqrt.m │ ├── ssinint.m │ ├── subs.m │ ├── subsasgn.m │ ├── subsindex.m │ ├── subsref.m │ ├── sum.m │ ├── svd.m │ ├── sym.m │ ├── sym2poly.m │ ├── symprod.m │ ├── sympy.m │ ├── symreplace.m │ ├── symsum.m │ ├── symvar.m │ ├── tan.m │ ├── tand.m │ ├── tanh.m │ ├── taylor.m │ ├── times.m │ ├── toeplitz.m │ ├── trace.m │ ├── transpose.m │ ├── tril.m │ ├── triu.m │ ├── uminus.m │ ├── union.m │ ├── unique.m │ ├── uplus.m │ ├── vertcat.m │ ├── xor.m │ ├── zeros.m │ ├── zeta.m │ └── ztrans.m ├── @symfun │ ├── argnames.m │ ├── diff.m │ ├── formula.m │ ├── int.m │ ├── isequal.m │ ├── isequaln.m │ ├── ldivide.m │ ├── minus.m │ ├── mldivide.m │ ├── mpower.m │ ├── mrdivide.m │ ├── mtimes.m │ ├── numel.m │ ├── plus.m │ ├── power.m │ ├── private │ │ └── helper_symfun_binops.m │ ├── private_disp_name.m │ ├── rdivide.m │ ├── size.m │ ├── subsref.m │ ├── symfun.m │ ├── symvar.m │ ├── times.m │ └── uminus.m ├── assume.m ├── assumptions.m ├── catalan.m ├── cell2sym.m ├── digits.m ├── dirac.m ├── eulergamma.m ├── fibonacci.m ├── findsymbols.m ├── finiteset.m ├── heaviside.m ├── laguerreL.m ├── lambertw.m ├── misc.tst ├── octsympy_tests.m ├── poly2sym.m ├── private │ ├── assert_have_python_and_sympy.m │ ├── assert_pythonic_and_sympy.m │ ├── check_and_convert.m │ ├── cygpath.m │ ├── defaultpython.m │ ├── do_highbyte_escapes.m │ ├── extractblock.m │ ├── get_sym_from_python.m │ ├── indent_lines.m │ ├── octave_array_to_python.m │ ├── python_copy_vars_from.m │ ├── python_copy_vars_to.m │ ├── python_env_is_cygwin_like.m │ ├── python_header.m │ ├── python_header.py │ ├── python_ipc_driver.m │ ├── python_ipc_native.m │ ├── python_ipc_popen2.m │ ├── python_ipc_sysoneline.m │ ├── python_ipc_system.m │ ├── readblock.m │ ├── show_system_info.m │ ├── store_vars_in_python.m │ ├── undo_highbyte_escapes.m │ ├── valid_sym_assumptions.m │ └── write_lines.m ├── pycall_sympy__.m ├── sympref.m ├── syms.m ├── test_bugs.tst ├── vpa.m └── vpasolve.m ├── io.github.gnu_octave.symbolic.metainfo.xml ├── matlab_smt_differences.md ├── misc ├── .oct-config ├── extract_tests_for_matlab.m ├── my_print_usage.m ├── octassert.m └── octsympy_tests_matlab.m ├── screenshot-install.png ├── screenshot.png └── util ├── .oct-config ├── Makefile ├── convert_comments.m ├── generate_functions.py └── make_windows_package.sh /.codespell-ignorelines: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: FSFAP 2 | # Copyright (C) 2024 Colin B. Macdonald 3 | # 4 | # Copying and distribution of this file, with or without modification, 5 | # are permitted in any medium without royalty provided the copyright 6 | # notice and this notice are preserved. This file is offered as-is, 7 | # without any warranty. 8 | 9 | # lines that codespell should ignore: whitespace matters! 10 | 11 | %!error 12 | -------------------------------------------------------------------------------- /.codespell-ignorewords: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: FSFAP 2 | # Copyright (C) 2024 Colin B. Macdonald 3 | # 4 | # Copying and distribution of this file, with or without modification, 5 | # are permitted in any medium without royalty provided the copyright 6 | # notice and this notice are preserved. This file is offered as-is, 7 | # without any warranty. 8 | 9 | # words that codespell should not complain about 10 | ans 11 | nin 12 | te 13 | unequalities 14 | unequality 15 | assignin 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: FSFAP 2 | # Copyright (C) 2024 Colin B. Macdonald 3 | # 4 | # Copying and distribution of this file, with or without modification, 5 | # are permitted in any medium without royalty provided the copyright 6 | # notice and this notice are preserved. This file is offered as-is, 7 | # without any warranty. 8 | # 9 | # Git ignore file for Octave's Symbolic package. 10 | 11 | *.so 12 | *~ 13 | 14 | octave-workspace 15 | 16 | # temporary communication files 17 | temp_sym_python_cmd.py 18 | inlog.txt 19 | outlog.txt 20 | octsympy_tests.log 21 | fntests.log 22 | 23 | # packaging subdir 24 | tmp/ 25 | 26 | # autoconf 27 | src/configure 28 | src/config.log 29 | src/aclocal.m4 30 | src/autom4te.cache 31 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | # Prevent git from showing duplicate names with commands like "git shortlog" 2 | # See the manpage of git-shortlog for details. 3 | # The syntax is: 4 | # Name that should be used Bad name 5 | # 6 | # You can skip Bad name if it is the same as the one that should be used, and is unique. 7 | # 8 | # This file is up-to-date if the command git log --format="%aN <%aE>" | sort -u 9 | # gives no duplicates. 10 | Colin B. Macdonald Colin Macdonald 11 | Colin B. Macdonald Colin B. Macdonald 12 | Colin B. Macdonald Colin Macdonald 13 | Abhinav Tripathi Abhinav 14 | Abhinav Tripathi 15 | Carnë Draug carandraug 16 | Carnë Draug 17 | John W. Eaton jwe 18 | Mike Miller 19 | Andrés Prieto maprieto 20 | utkarsh utkarsh 21 | Orion Poplawski opoplawski 22 | Alex Vong alexvong1995 <10696787+alexvong1995@users.noreply.github.com> 23 | Alex Vong 24 | Alex Vong 25 | Rafael Laboissiere rlaboiss 26 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Authors and Contributors 2 | ======================== 3 | 4 | Colin B. Macdonald 5 | Willem J. Atsma 6 | Andrés Prieto 7 | Carnë Draug 8 | Vadim Gribanov 9 | Alexander Misel 10 | Mike Miller 11 | Lagu 12 | Abhinav Tripathi 13 | Utkarsh Gautam 14 | Eric Chassande-Mottin 15 | Nicol N. Schraudolph 16 | Sylvain Pelissier 17 | Alex Vong 18 | Marco Falke 19 | NVS Abhilash 20 | Orion Poplawski 21 | Osella Giancarlo 22 | Olaf Till 23 | Tasos Papastylianou 24 | Tianyu Chen (billchenchina) 25 | Johannes Maria Frank 26 | Chris Gorman 27 | Fernando Alvarruiz 28 | Jing-Chen Peng 29 | Rafael Laboissière 30 | Cédric M. Campos 31 | Swayam Shah 32 | 33 | (Please contact the developers if your name should be here but isn't!) 34 | 35 | 36 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 37 | 38 | Thanks also to the authors of the original GiNaC-based symbolic 39 | package: 40 | 41 | Ben Sapp 42 | pkienzle 43 | Michael Goffioul 44 | Willem J. Atsma 45 | Rafael Laboissiere 46 | Thomas Weber 47 | adb014 48 | hauberg 49 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Name: symbolic 2 | Version: 3.2.1+ 3 | Date: 2024-05-16 4 | Author: Colin B. Macdonald 5 | Maintainer: Colin B. Macdonald 6 | Title: Octave Symbolic Package using SymPy 7 | Description: Adds symbolic calculation features to GNU Octave. These 8 | include common Computer Algebra System tools such as algebraic operations, 9 | calculus, equation solving, Fourier and Laplace transforms, variable 10 | precision arithmetic and other features. Compatibility with other symbolic 11 | toolboxes is intended. 12 | Categories: symbolic 13 | Url: https://octave.sourceforge.io/symbolic 14 | Depends: octave (>= 6.1) 15 | SystemRequirements: python, sympy (>= 1.5.1), mpmath (>= 1.0) 16 | License: GPL-3.0-or-later 17 | -------------------------------------------------------------------------------- /README.matlab.md: -------------------------------------------------------------------------------- 1 | OctSymPy for Matlab 2 | =================== 3 | 4 | README.md is the main document. Here we list any Matlab-specific notes. 5 | 6 | Formatting: Matlab uses a different formatting for comment headers. 7 | Most of the .m files have been autoconverted from the GNU Octave 8 | versions. 9 | 10 | Tests: Many .m files have tests built-in using using Octave's test framework. 11 | These have been autoextracted for Matlab (which unfortunately doesn't use the 12 | same test framework). 13 | 14 | 15 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnu-octave/symbolic/56ee3f2bd10b031ab30f293d0cb6c9a99ae47b7b/icon.png -------------------------------------------------------------------------------- /inst/.oct-config: -------------------------------------------------------------------------------- 1 | encoding=utf-8 2 | -------------------------------------------------------------------------------- /inst/@logical/isAlways.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@logical isAlways (@var{t}) 22 | %% Test if expression is mathematically true. 23 | %% 24 | %% For inputs of type logical (true/false) this is just the 25 | %% logical itself. The reason for having this function is 26 | %% explained elsewhere (@pxref{@@sym/isAlways}). 27 | %% 28 | %% Examples: 29 | %% @example 30 | %% @group 31 | %% isAlways(true) 32 | %% @result{} ans = 1 33 | %% isAlways(false) 34 | %% @result{} ans = 0 35 | %% @end group 36 | %% @end example 37 | %% 38 | %% @seealso{@@sym/isAlways} 39 | %% @end defmethod 40 | 41 | 42 | function r = isAlways(p) 43 | 44 | if (nargin ~= 1) 45 | print_usage (); 46 | end 47 | 48 | r = p; 49 | 50 | end 51 | 52 | 53 | %!error isAlways (true, false) 54 | %!assert(isAlways(true)) 55 | %!assert(~isAlways(false)) 56 | -------------------------------------------------------------------------------- /inst/@sym/abs.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym abs (@var{x}) 22 | %% Symbolic abs function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = abs (x) 29 | %% @result{} y = (sym) │x│ 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = abs(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('Abs', x); 44 | end 45 | 46 | 47 | %!error abs (sym(1), 2) 48 | %!assert (isequaln (abs (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = -1; 52 | %! x = sym('-1'); 53 | 54 | %!test 55 | %! f1 = abs(x); 56 | %! f2 = abs(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = abs(A); 63 | %! f2 = abs(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = abs (d); 70 | %! f = abs (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/acos.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym acos (@var{x}) 22 | %% Symbolic acos function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = acos (x) 29 | %% @result{} y = (sym) acos(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = acos(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('acos', x); 44 | end 45 | 46 | 47 | %!error acos (sym(1), 2) 48 | %!assert (isequaln (acos (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = acos(x); 56 | %! f2 = acos(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = acos(A); 63 | %! f2 = acos(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = acos (d); 70 | %! f = acos (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/acosd.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym acosd (@var{x}) 22 | %% Symbolic inverse cos function with output in degrees. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% acosd (sqrt (sym (2))/2) 28 | %% @result{} (sym) 45 29 | %% 30 | %% syms x 31 | %% y = acosd (x) 32 | %% @result{} y = (sym) 33 | %% 180⋅acos(x) 34 | %% ─────────── 35 | %% π 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/cosd, @@sym/acos} 40 | %% @end defmethod 41 | 42 | 43 | function y = acosd(x) 44 | if (nargin ~= 1) 45 | print_usage (); 46 | end 47 | y = elementwise_op ('lambda a: deg(acos(a))', x); 48 | end 49 | 50 | 51 | %!error acosd (sym(1), 2) 52 | %!assert (isequaln (acosd (sym(nan)), sym(nan))) 53 | 54 | %!test 55 | %! f1 = acosd (sym(1)/2); 56 | %! f2 = acosd (1/2); 57 | %! assert (double (f1), f2, -eps) 58 | 59 | %!test 60 | %! D = [1 2; 3 4]/4; 61 | %! A = sym([1 2; 3 4])/4; 62 | %! f1 = acosd (A); 63 | %! f2 = acosd (D); 64 | %! assert (double (f1), f2, -eps) 65 | -------------------------------------------------------------------------------- /inst/@sym/acot.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym acot (@var{x}) 22 | %% Symbolic acot function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = acot (x) 29 | %% @result{} y = (sym) acot(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = acot(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('acot', x); 44 | end 45 | 46 | 47 | %!error acot (sym(1), 2) 48 | %!assert (isequaln (acot (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = acot(x); 56 | %! f2 = acot(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = acot(A); 63 | %! f2 = acot(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = acot (d); 70 | %! f = acot (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/acsc.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym acsc (@var{x}) 22 | %% Symbolic acsc function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = acsc (x) 29 | %% @result{} y = (sym) acsc(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = acsc(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('acsc', x); 44 | end 45 | 46 | 47 | %!error acsc (sym(1), 2) 48 | %!assert (isequaln (acsc (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = acsc(x); 56 | %! f2 = acsc(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = acsc(A); 63 | %! f2 = acsc(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = acsc (d); 70 | %! f = acsc (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/angle.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% Copyright (C) 2018-2019 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @documentencoding UTF-8 22 | %% @defmethod @@sym angle (@var{x}) 23 | %% @defmethodx @@sym arg (@var{x}) 24 | %% Symbolic polar angle. 25 | %% 26 | %% Example: 27 | %% @example 28 | %% @group 29 | %% x = sym(2+3*i); 30 | %% y = angle(x) 31 | %% @result{} y = (sym) atan(3/2) 32 | %% @end group 33 | %% @end example 34 | %% @seealso{angle, @@sym/abs} 35 | %% @end defmethod 36 | 37 | 38 | function y = angle (x) 39 | if (nargin ~= 1) 40 | print_usage (); 41 | end 42 | y = elementwise_op ('arg', x); 43 | end 44 | 45 | 46 | %!test 47 | %! Z = [sqrt(sym(3)) + 3*sym(i), 3 + sqrt(sym(3))*sym(i); 1 + sym(i), sym(i)]; 48 | %! Q = [sym(pi)/3 sym(pi)/6; sym(pi)/4 sym(pi)/2]; 49 | %! assert( isequal( angle(Z), Q)); 50 | 51 | %!test 52 | %! % roundtrip 53 | %! syms x 54 | %! A = angle (2+2i); 55 | %! f = angle (x); 56 | %! h = function_handle (f); 57 | %! B = h (2+2i); 58 | %! assert (A, B, -eps) 59 | -------------------------------------------------------------------------------- /inst/@sym/arg.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2018 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym arg (@var{x}) 22 | %% @defmethodx @@sym angle (@var{x}) 23 | %% Symbolic polar angle. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% x = sym(2+3*i); 29 | %% y = arg(x) 30 | %% @result{} y = (sym) atan(3/2) 31 | %% @end group 32 | %% @end example 33 | %% @seealso{arg, @@sym/abs} 34 | %% @end defmethod 35 | 36 | 37 | function y = arg (x) 38 | if (nargin ~= 1) 39 | print_usage (); 40 | end 41 | y = elementwise_op ('arg', x); 42 | end 43 | 44 | 45 | %!test 46 | %! syms x 47 | %! assert (isequal (angle (x), arg (x))); 48 | -------------------------------------------------------------------------------- /inst/@sym/argnames.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym argnames (@var{f}) 22 | %% Return the independent variables in a symfun. 23 | %% 24 | %% For a @@sym, this always returns the empty sym, but 25 | %% subclasses like @@symfun do something more interesting. 26 | %% 27 | %% Example: 28 | %% @example 29 | %% @group 30 | %% syms x y 31 | %% f = 2*x*y; 32 | %% argnames(f) 33 | %% @result{} (sym) [] (empty 0×0 matrix) 34 | %% @end group 35 | %% @end example 36 | %% 37 | %% @seealso{@@symfun/argnames, symvar, findsym, findsymbols} 38 | %% @end defmethod 39 | 40 | 41 | function vars = argnames(F) 42 | 43 | vars = sym([]); 44 | 45 | end 46 | 47 | 48 | %!test 49 | %! % basic tests 50 | %! syms x 51 | %! f = 2*x; 52 | %! assert (isempty (argnames(x))) 53 | %! assert (isempty (argnames(f))) 54 | -------------------------------------------------------------------------------- /inst/@sym/asec.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym asec (@var{x}) 22 | %% Symbolic asec function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = asec (x) 29 | %% @result{} y = (sym) asec(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = asec(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('asec', x); 44 | end 45 | 46 | 47 | %!error asec (sym(1), 2) 48 | %!assert (isequaln (asec (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 2; 52 | %! x = sym('2'); 53 | 54 | %!test 55 | %! f1 = asec(x); 56 | %! f2 = asec(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = asec(A); 63 | %! f2 = asec(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = asec (d); 70 | %! f = asec (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/asin.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym asin (@var{x}) 22 | %% Symbolic asin function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = asin (x) 29 | %% @result{} y = (sym) asin(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = asin(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('asin', x); 44 | end 45 | 46 | 47 | %!error asin (sym(1), 2) 48 | %!assert (isequaln (asin (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = asin(x); 56 | %! f2 = asin(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = asin(A); 63 | %! f2 = asin(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = asin (d); 70 | %! f = asin (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/asind.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym asind (@var{x}) 22 | %% Symbolic inverse sin function with output in degrees. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% asind (sqrt (sym (2))/2) 28 | %% @result{} (sym) 45 29 | %% 30 | %% syms x 31 | %% y = asind (x) 32 | %% @result{} y = (sym) 33 | %% 180⋅asin(x) 34 | %% ─────────── 35 | %% π 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/sind, @@sym/asin} 40 | %% @end defmethod 41 | 42 | 43 | function y = asind(x) 44 | if (nargin ~= 1) 45 | print_usage (); 46 | end 47 | y = elementwise_op ('lambda a: deg(asin(a))', x); 48 | end 49 | 50 | 51 | %!error asind (sym(1), 2) 52 | %!assert (isequaln (asind (sym(nan)), sym(nan))) 53 | 54 | %!test 55 | %! f1 = asind (sym(1)/2); 56 | %! f2 = asind (1/2); 57 | %! assert (double (f1), f2, -eps) 58 | 59 | %!test 60 | %! D = [1 2; 3 4]/4; 61 | %! A = sym([1 2; 3 4])/4; 62 | %! f1 = asind (A); 63 | %! f2 = asind (D); 64 | %! assert (double (f1), f2, -eps) 65 | -------------------------------------------------------------------------------- /inst/@sym/atan.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym atan (@var{x}) 22 | %% Symbolic atan function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = atan (x) 29 | %% @result{} y = (sym) atan(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = atan(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('atan', x); 44 | end 45 | 46 | 47 | %!error atan (sym(1), 2) 48 | %!assert (isequaln (atan (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = atan(x); 56 | %! f2 = atan(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = atan(A); 63 | %! f2 = atan(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = atan (d); 70 | %! f = atan (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/atand.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym atand (@var{x}) 22 | %% Symbolic inverse tan function with output in degrees. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% atand (sqrt (sym (3))) 28 | %% @result{} (sym) 60 29 | %% 30 | %% syms x 31 | %% y = atand (x) 32 | %% @result{} y = (sym) 33 | %% 180⋅atan(x) 34 | %% ─────────── 35 | %% π 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/tand, @@sym/atan} 40 | %% @end defmethod 41 | 42 | 43 | function y = atand(x) 44 | if (nargin ~= 1) 45 | print_usage (); 46 | end 47 | y = elementwise_op ('lambda a: deg(atan(a))', x); 48 | end 49 | 50 | 51 | %!error atand (sym(1), 2) 52 | %!assert (isequaln (atand (sym(nan)), sym(nan))) 53 | 54 | %!test 55 | %! f1 = atand (sym(1)/2); 56 | %! f2 = atand (1/2); 57 | %! assert (double (f1), f2, -eps) 58 | 59 | %!test 60 | %! D = [1 2; 3 4]/4; 61 | %! A = sym([1 2; 3 4])/4; 62 | %! f1 = atand (A); 63 | %! f2 = atand (D); 64 | %! assert (double (f1), f2, -eps) 65 | -------------------------------------------------------------------------------- /inst/@sym/besseli.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym besseli (@var{alpha}, @var{x}) 22 | %% Symbolic modified Bessel function of the first kind. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms n x 28 | %% A = 2*besseli(n,x) 29 | %% @result{} A = (sym) 2⋅besseli(n, x) 30 | %% diff(A) 31 | %% @result{} (sym) besseli(n - 1, x) + besseli(n + 1, x) 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/besselk, @@sym/besselj, @@sym/bessely} 36 | %% @end defmethod 37 | 38 | function I = besseli(n, x) 39 | 40 | if (nargin ~= 2) 41 | print_usage (); 42 | end 43 | 44 | I = elementwise_op ('besseli', sym(n), sym(x)); 45 | 46 | end 47 | 48 | 49 | %!test 50 | %! X = [1 2 3; 4 5 6]; 51 | %! ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; 52 | %! n = double(ns); 53 | %! A = double(besseli(ns, X)); 54 | %! B = besseli(n, X); 55 | %! assert (all (all (abs (A - B) < 100*eps*abs(A)))) 56 | 57 | %!test 58 | %! % roundtrip 59 | %! syms x 60 | %! A = besseli(2, 10); 61 | %! q = besseli(2, x); 62 | %! h = function_handle(q); 63 | %! B = h(10); 64 | %! assert (abs (A - B) <= eps*abs(A)) 65 | 66 | %!error besseli(sym('x')) 67 | -------------------------------------------------------------------------------- /inst/@sym/besselj.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym besselj (@var{alpha}, @var{x}) 22 | %% Symbolic Bessel function of the first kind. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms n x 28 | %% A = 2*besselj(n,x) 29 | %% @result{} A = (sym) 2⋅besselj(n, x) 30 | %% diff(A) 31 | %% @result{} (sym) besselj(n - 1, x) - besselj(n + 1, x) 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/bessely, @@sym/besseli, @@sym/besselk} 36 | %% @end defmethod 37 | 38 | function J = besselj(n, x) 39 | 40 | if (nargin ~= 2) 41 | print_usage (); 42 | end 43 | 44 | J = elementwise_op ('besselj', sym(n), sym(x)); 45 | 46 | end 47 | 48 | 49 | %!test 50 | %! X = [1 2 3; 4 5 6]; 51 | %! ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; 52 | %! n = double(ns); 53 | %! A = double(besselj(ns, X)); 54 | %! B = besselj(n, X); 55 | %! assert (all (all (abs (A - B) < 50*eps*abs(A)))) 56 | 57 | %!test 58 | %! % roundtrip 59 | %! syms x 60 | %! A = besselj(2, 10); 61 | %! q = besselj(2, x); 62 | %! h = function_handle(q); 63 | %! B = h(10); 64 | %! assert (abs (A - B) <= eps*abs(A)) 65 | 66 | %!error besselj(sym('x')) 67 | -------------------------------------------------------------------------------- /inst/@sym/besseljn.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Utkarsh Gautam 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym besseljn (@var{alpha}, @var{x}) 22 | %% Symbolic Spherical Bessel function of the first kind. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms n x 28 | %% A = besseljn(n, x) 29 | %% @result{} A = (sym) jn(n, x) 30 | %% diff(A) 31 | %% @result{} ans = (sym) 32 | %% 33 | %% (n + 1)⋅jn(n, x) 34 | %% jn(n - 1, x) - ──────────────── 35 | %% x 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/besselyn, @@sym/besselj} 40 | %% @end defmethod 41 | 42 | function Y = besseljn(n, x) 43 | if (nargin ~= 2) 44 | print_usage (); 45 | end 46 | Y = elementwise_op ('jn', sym(n), sym(x)); 47 | end 48 | 49 | 50 | %!test 51 | %! % roundtrip 52 | %! syms x 53 | %! A = double(besseljn(sym(2), sym(9))); 54 | %! q = besseljn(sym(2), x); 55 | %! h = function_handle(q); 56 | %! B = h(9); 57 | %! assert (abs (A - B) <= eps) 58 | 59 | %!error jn(sym('x')) 60 | -------------------------------------------------------------------------------- /inst/@sym/besselk.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym besselk (@var{alpha}, @var{x}) 22 | %% Symbolic modified Bessel function of the second kind. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms n x 28 | %% A = 2*besselk(n,x) 29 | %% @result{} A = (sym) 2⋅besselk(n, x) 30 | %% diff(A) 31 | %% @result{} (sym) -besselk(n - 1, x) - besselk(n + 1, x) 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/besseli, @@sym/besselj, @@sym/bessely} 36 | %% @end defmethod 37 | 38 | function K = besselk(n, x) 39 | 40 | if (nargin ~= 2) 41 | print_usage (); 42 | end 43 | 44 | K = elementwise_op ('besselk', sym(n), sym(x)); 45 | 46 | end 47 | 48 | 49 | %!test 50 | %! X = [1 2 3; 4 5 6]; 51 | %! ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; 52 | %! n = double(ns); 53 | %! A = double(besselk(ns, X)); 54 | %! B = besselk(n, X); 55 | %! assert (all (all (abs (A - B) < 2*eps*abs(A)))) 56 | 57 | %!test 58 | %! % roundtrip 59 | %! syms x 60 | %! A = besselk(2, 10); 61 | %! q = besselk(2, x); 62 | %! h = function_handle(q); 63 | %! B = h(10); 64 | %! assert (abs (A - B) <= eps*abs(A)) 65 | 66 | %!error besselk(sym('x')) 67 | -------------------------------------------------------------------------------- /inst/@sym/bessely.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym bessely (@var{alpha}, @var{x}) 22 | %% Symbolic Bessel function of the second kind. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms n x 28 | %% A = 2*bessely(n, x) 29 | %% @result{} A = (sym) 2⋅bessely(n, x) 30 | %% diff(A) 31 | %% @result{} (sym) bessely(n - 1, x) - bessely(n + 1, x) 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/besselj, @@sym/besseli, @@sym/besselk} 36 | %% @end defmethod 37 | 38 | function Y = bessely(n, x) 39 | 40 | if (nargin ~= 2) 41 | print_usage (); 42 | end 43 | 44 | Y = elementwise_op ('bessely', sym(n), sym(x)); 45 | 46 | end 47 | 48 | 49 | %!test 50 | %! X = [1 2 3; 4 5 6]; 51 | %! ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; 52 | %! n = double(ns); 53 | %! A = double(bessely(ns, X)); 54 | %! B = bessely(n, X); 55 | %! assert (all (all (abs (A - B) < 50*eps*abs(A)))) 56 | 57 | %!test 58 | %! % roundtrip 59 | %! syms x 60 | %! A = bessely(2, 10); 61 | %! q = bessely(2, x); 62 | %! h = function_handle(q); 63 | %! B = h(10); 64 | %! assert (abs (A - B) <= eps*abs(A)) 65 | 66 | %!error bessely(sym('x')) 67 | -------------------------------------------------------------------------------- /inst/@sym/besselyn.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Utkarsh Gautam 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym besselyn (@var{alpha}, @var{x}) 22 | %% Symbolic Spherical Bessel function of the second kind. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms n x 28 | %% A = besselyn(n, x) 29 | %% @result{} A = (sym) yn(n, x) 30 | %% diff(A) 31 | %% @result{} ans = (sym) 32 | %% 33 | %% (n + 1)⋅yn(n, x) 34 | %% yn(n - 1, x) - ──────────────── 35 | %% x 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/besseljn, @@sym/bessely} 40 | %% @end defmethod 41 | 42 | function Y = besselyn(n, x) 43 | if (nargin ~= 2) 44 | print_usage (); 45 | end 46 | Y = elementwise_op ('yn', sym(n), sym(x)); 47 | end 48 | 49 | 50 | 51 | %!test 52 | %! % roundtrip 53 | %! syms x 54 | %! A = double(besselyn(sym(2), sym(10))); 55 | %! q = besselyn(sym(2), x); 56 | %! h = function_handle(q); 57 | %! B = h(10); 58 | %! assert (abs (A - B) <= eps) 59 | 60 | %!error yn(sym('x')) 61 | -------------------------------------------------------------------------------- /inst/@sym/beta.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% Copyright (C) 2018-2019, 2022, 2024 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @documentencoding UTF-8 22 | %% @defmethod @@sym beta (@var{x}, @var{y}) 23 | %% Beta function. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x y 29 | %% beta(x, y) 30 | %% @result{} ans = (sym) Β(x, y) 31 | %% @end group 32 | %% @end example 33 | %% 34 | %% The beta function is related to the gamma function: 35 | %% @example 36 | %% @group 37 | %% rewrite (beta (x,y), "gamma") 38 | %% @result{} 39 | %% ans = (sym) 40 | %% Γ(x)⋅Γ(y) 41 | %% ───────── 42 | %% Γ(x + y) 43 | %% @end group 44 | %% @end example 45 | %% 46 | %% @seealso{@@sym/gamma} 47 | %% @end defmethod 48 | 49 | 50 | function r = beta(x, y) 51 | 52 | if (nargin ~= 2) 53 | print_usage (); 54 | end 55 | 56 | r = elementwise_op ('beta', sym(x), sym(y)); 57 | 58 | end 59 | 60 | 61 | %!error beta (sym(1), 2, 3) 62 | 63 | %!assert (isequal (double (beta (sym(1), 2)), 1/2)) 64 | %!assert (isinf (double (beta (sym(1), 0)))) 65 | 66 | %!test 67 | %! % round trip 68 | %! syms x y 69 | %! f = beta (x, y); 70 | %! h = function_handle (f); 71 | %! A = h (1.1, 2.2); 72 | %! B = beta (1.1, 2.2); 73 | %! assert (A, B) 74 | -------------------------------------------------------------------------------- /inst/@sym/cat.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym cat (@var{dim}, @var{A}, @var{B}, @dots{}) 22 | %% Concatenate symbolic arrays along particular dimension. 23 | %% 24 | %% @var{dim} is currently restricted to 1 or 2 as symbolic arrays 25 | %% are currently only two-dimensional. 26 | %% 27 | %% Example: 28 | %% @example 29 | %% @group 30 | %% syms x 31 | %% cat(1, x, 2*x, 3*x) 32 | %% @result{} (sym) [x 2⋅x 3⋅x] (1×3 matrix) 33 | %% cat(2, x, x) 34 | %% @result{} (sym 2×1 matrix) 35 | %% ⎡x⎤ 36 | %% ⎢ ⎥ 37 | %% ⎣x⎦ 38 | %% @end group 39 | %% @end example 40 | %% @seealso{@@sym/vertcat, @@sym/horzcat} 41 | %% @end defmethod 42 | 43 | 44 | function z = cat(dim, varargin) 45 | 46 | if (logical(dim == 1)) 47 | z = horzcat(varargin{:}); 48 | elseif (logical(dim == 2)) 49 | z = vertcat(varargin{:}); 50 | else 51 | print_usage (); 52 | end 53 | 54 | end 55 | 56 | 57 | %!test 58 | %! % mostly tested in horzcat, vertcat: one for good measure 59 | %! syms x 60 | %! assert (isequal (cat(1, x, x), [x x])) 61 | %! assert (isequal (cat(2, x, x), [x; x])) 62 | 63 | %!error cat(3, sym(2), sym(3)) 64 | %!error cat(0, sym(2), sym(3)) 65 | -------------------------------------------------------------------------------- /inst/@sym/columns.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym columns (@var{x}) 22 | %% Return the number of columns in a symbolic array. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = [1 2 sym(pi); 4 5 2*sym(pi)]; 28 | %% m = columns (A) 29 | %% @result{} m = 3 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% @seealso{@@sym/rows, @@sym/size, @@sym/length, @@sym/numel} 34 | %% @end defmethod 35 | 36 | 37 | function n = columns(x) 38 | 39 | n = size(x, 2); 40 | 41 | end 42 | 43 | 44 | %!test 45 | %! a = sym([1 2 3]); 46 | %! assert (columns(a) == 3) 47 | 48 | %!test 49 | %! a = sym([1; 2]); 50 | %! assert (columns(a) == 1) 51 | -------------------------------------------------------------------------------- /inst/@sym/cond.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym cond (@var{A}) 22 | %% Symbolic condition number of a symbolic matrix. 23 | %% 24 | %% Examples: 25 | %% @example 26 | %% @group 27 | %% A = sym([1 2; 3 0]); 28 | %% cond(A)^2 29 | %% @result{} (sym) 30 | %% 31 | %% √13 + 7 32 | %% ─────── 33 | %% 7 - √13 34 | %% @end group 35 | %% @end example 36 | %% 37 | %% @seealso{@@sym/svd} 38 | %% @end defmethod 39 | 40 | 41 | function k = cond(A) 42 | 43 | cmd = { '(A,) = _ins' ... 44 | 'if not A.is_Matrix:' ... 45 | ' A = sp.Matrix([A])' ... 46 | 'return A.condition_number(),' }; 47 | 48 | k = pycall_sympy__ (cmd, sym(A)); 49 | 50 | end 51 | 52 | 53 | %!test 54 | %! A = [1 2; 3 4]; 55 | %! B = sym(A); 56 | %! k1 = cond(A); 57 | %! k2 = cond(B); 58 | %! k3 = double(k2); 59 | %! assert (k1 - k3 <= 100*eps) 60 | 61 | %!test 62 | %! % matrix with symbols 63 | %! syms x positive 64 | %! A = [x 0; sym(0) 2*x]; 65 | %! k1 = cond(A); 66 | %! assert (isequal (k1, sym(2))) 67 | -------------------------------------------------------------------------------- /inst/@sym/cos.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym cos (@var{x}) 22 | %% Symbolic cos function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = cos (x) 29 | %% @result{} y = (sym) cos(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = cos(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('cos', x); 44 | end 45 | 46 | 47 | %!error cos (sym(1), 2) 48 | %!assert (isequaln (cos (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = cos(x); 56 | %! f2 = cos(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = cos(A); 63 | %! f2 = cos(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = cos (d); 70 | %! f = cos (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/cosd.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym cosd (@var{x}) 22 | %% Symbolic cos function with input in degrees. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% cosd (sym (60)) 28 | %% @result{} (sym) 1/2 29 | %% 30 | %% syms x 31 | %% y = cosd (x) 32 | %% @result{} y = (sym) 33 | %% ⎛π⋅x⎞ 34 | %% cos⎜───⎟ 35 | %% ⎝180⎠ 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/acosd, @@sym/cos} 40 | %% @end defmethod 41 | 42 | 43 | function y = cosd(x) 44 | if (nargin ~= 1) 45 | print_usage (); 46 | end 47 | y = elementwise_op ('lambda a: cos(rad(a))', x); 48 | end 49 | 50 | 51 | %!error cosd (sym(1), 2) 52 | %!assert (isequaln (cosd (sym(nan)), sym(nan))) 53 | 54 | %!test 55 | %! f1 = cosd (sym(1)); 56 | %! f2 = cosd (1); 57 | %! assert (double (f1), f2, -eps) 58 | 59 | %!test 60 | %! D = [10 30; 110 -45]; 61 | %! A = sym(D); 62 | %! f1 = cosd (A); 63 | %! f2 = cosd (D); 64 | %! assert (double (f1), f2, -4*eps) 65 | -------------------------------------------------------------------------------- /inst/@sym/cosh.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym cosh (@var{x}) 22 | %% Symbolic cosh function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = cosh (x) 29 | %% @result{} y = (sym) cosh(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = cosh(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('cosh', x); 44 | end 45 | 46 | 47 | %!error cosh (sym(1), 2) 48 | %!assert (isequaln (cosh (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = cosh(x); 56 | %! f2 = cosh(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = cosh(A); 63 | %! f2 = cosh(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = cosh (d); 70 | %! f = cosh (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/cot.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym cot (@var{x}) 22 | %% Symbolic cot function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = cot (x) 29 | %% @result{} y = (sym) cot(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = cot(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('cot', x); 44 | end 45 | 46 | 47 | %!error cot (sym(1), 2) 48 | %!assert (isequaln (cot (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = cot(x); 56 | %! f2 = cot(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = cot(A); 63 | %! f2 = cot(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = cot (d); 70 | %! f = cot (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/coth.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym coth (@var{x}) 22 | %% Symbolic coth function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = coth (x) 29 | %% @result{} y = (sym) coth(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = coth(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('coth', x); 44 | end 45 | 46 | 47 | %!error coth (sym(1), 2) 48 | %!assert (isequaln (coth (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = coth(x); 56 | %! f2 = coth(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = coth(A); 63 | %! f2 = coth(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = coth (d); 70 | %! f = coth (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/csc.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym csc (@var{x}) 22 | %% Symbolic csc function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = csc (x) 29 | %% @result{} y = (sym) csc(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = csc(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('csc', x); 44 | end 45 | 46 | 47 | %!error csc (sym(1), 2) 48 | %!assert (isequaln (csc (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = csc(x); 56 | %! f2 = csc(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = csc(A); 63 | %! f2 = csc(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = csc (d); 70 | %! f = csc (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/csch.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym csch (@var{x}) 22 | %% Symbolic csch function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = csch (x) 29 | %% @result{} y = (sym) csch(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = csch(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('csch', x); 44 | end 45 | 46 | 47 | %!error csch (sym(1), 2) 48 | %!assert (isequaln (csch (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = csch(x); 56 | %! f2 = csch(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = csch(A); 63 | %! f2 = csch(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = csch (d); 70 | %! f = csch (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/dawson.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym dawson (@var{x}) 22 | %% Symbolic Dawson (scaled imaginary error) function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% dawson (x) 29 | %% @result{} ans = (sym) 30 | %% 2 31 | %% -x 32 | %% √π⋅ℯ ⋅erfi(x) 33 | %% ─────────────── 34 | %% 2 35 | %% @end group 36 | %% @end example 37 | %% @seealso{dawson, @@sym/erfc, @@sym/erf, @@sym/erfcx, @@sym/erfi, @@sym/erfinv, @@sym/erfcinv} 38 | %% @end defmethod 39 | 40 | 41 | function y = dawson(x) 42 | if (nargin ~= 1) 43 | print_usage (); 44 | end 45 | y = elementwise_op ('lambda a: exp(-a**2)*erfi(a)*(sqrt(S(pi))/2)', x); 46 | end 47 | 48 | 49 | %!test 50 | %! if (exist ('OCTAVE_VERSION', 'builtin')) 51 | %! % dawson missing on Matlab, Issue #742 52 | %! A = dawson([1 2]); 53 | %! B = double(dawson(sym([1 2]))); 54 | %! assert(A, B, -eps) 55 | %! end 56 | -------------------------------------------------------------------------------- /inst/@sym/det.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym det (@var{x}) 22 | %% Symbolic determinant of a matrix. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = sym([2 4; 6 8]); 28 | %% det(A) 29 | %% @result{} ans = (sym) -8 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% @seealso{@@sym/eig, @@sym/charpoly, @@sym/trace} 34 | %% @end defmethod 35 | 36 | 37 | function z = det(x) 38 | 39 | if (nargin ~= 1) 40 | print_usage (); 41 | end 42 | 43 | cmd = { '(A,) = _ins' 44 | 'if not A.is_Matrix:' 45 | ' A = sp.Matrix([A])' 46 | 'return A.det(),' }; 47 | 48 | z = pycall_sympy__ (cmd, x); 49 | 50 | end 51 | 52 | 53 | %!assert (isequal (det(sym([])), 1)) 54 | 55 | %!test 56 | %! syms x y real 57 | %! assert (isequal (det([x 5; 7 y]), x*y-35)) 58 | 59 | %!test 60 | %! syms x 61 | %! assert (isequal (det(x), x)) 62 | %! assert (isequal (det(sym(-6)), sym(-6))) 63 | 64 | -------------------------------------------------------------------------------- /inst/@sym/dilog.m: -------------------------------------------------------------------------------- 1 | %% SPDX-License-Identifier: GPL-3.0-or-later 2 | %% Copyright (C) 2016, 2018-2019, 2022-2024 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @documentencoding UTF-8 22 | %% @defmethod @@sym dilog (@var{z}) 23 | %% Symbolic dilogarithm function. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms z 29 | %% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) >= Version("1.13.0")')) 30 | %% dilog (z) 31 | %% @result{} ans = (sym) Li₂(1 - z) 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/polylog} 36 | %% @end defmethod 37 | 38 | function L = dilog(z) 39 | if (nargin ~= 1) 40 | print_usage (); 41 | end 42 | 43 | L = polylog(2, 1 - z); 44 | end 45 | 46 | 47 | %!assert (isequal (dilog (sym(1)), sym(0))) 48 | %!assert (isequal (dilog (sym(0)), sym(pi)^2/6)) 49 | 50 | %!assert (isequal (dilog (sym(2)), -sym(pi)^2/12)) 51 | 52 | %!assert (double(dilog(sym(-1))), pi^2/4 - pi*1i*log(2), eps) 53 | 54 | %!test 55 | %! % round-trip 56 | %! syms x 57 | %! f = dilog (x); 58 | %! h = function_handle (f); 59 | %! A = h (1.1); 60 | %! B = dilog (1.1); 61 | %! assert (A, B, -eps) 62 | -------------------------------------------------------------------------------- /inst/@sym/divisors.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% Copyright (C) 2019 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @documentencoding UTF-8 22 | %% @defmethod @@sym divisors (@var{x}) 23 | %% Get divisors of integer. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% x = sym(150); 29 | %% y = divisors(x) 30 | %% @result{} y = (sym) [1 2 3 5 6 10 15 25 30 50 75 150] (1×12 matrix) 31 | %% @end group 32 | %% @end example 33 | %% @end defmethod 34 | 35 | %% Reference: http://docs.sympy.org/dev/modules/ntheory.html 36 | 37 | 38 | function y = divisors(x) 39 | if (nargin ~= 1) 40 | print_usage (); 41 | end 42 | y = pycall_sympy__ ('return S(divisors(_ins[0])),', x); 43 | y = cell2sym(y); 44 | end 45 | 46 | 47 | %!test 48 | %! assert( isequal( divisors(sym(150)), divisors(sym(-150)) )) 49 | -------------------------------------------------------------------------------- /inst/@sym/ellipke.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016-2017 Lagu 2 | %% Copyright (C) 2017, 2022 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @documentencoding UTF-8 22 | %% @defmethod @@sym [@var{K}, @var{E}] = ellipke (@var{m}) 23 | %% Complete elliptic integrals of the first and second kinds. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms m 29 | %% [K, E] = ellipke (m) 30 | %% @result{} K = (sym) K(m) 31 | %% @result{} E = (sym) E(m) 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{ellipke, @@sym/ellipticK, @@sym/ellipticE} 36 | %% @end defmethod 37 | 38 | 39 | function varargout = ellipke(m) 40 | 41 | if (nargin ~= 1 || nargout > 2) 42 | print_usage (); 43 | end 44 | 45 | if (nargout == 0 || nargout == 1) 46 | varargout = {ellipticK(m)}; 47 | else 48 | varargout = {ellipticK(m) ellipticE(m)}; 49 | end 50 | 51 | end 52 | 53 | 54 | %!error ellipke (sym(1), 2) 55 | 56 | %!test 57 | %! for i = 2:10 58 | %! [K E] = ellipke (sym (1)/i); 59 | %! [k e] = ellipke (1/i); 60 | %! assert (double ([K E]), [k e], 2*eps) 61 | %! end 62 | -------------------------------------------------------------------------------- /inst/@sym/erf.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym erf (@var{x}) 22 | %% Symbolic erf function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = erf (x) 29 | %% @result{} y = (sym) erf(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = erf(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('erf', x); 44 | end 45 | 46 | 47 | %!error erf (sym(1), 2) 48 | %!assert (isequaln (erf (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = erf(x); 56 | %! f2 = erf(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = erf(A); 63 | %! f2 = erf(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = erf (d); 70 | %! f = erf (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/erfc.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym erfc (@var{x}) 22 | %% Symbolic erfc function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = erfc (x) 29 | %% @result{} y = (sym) erfc(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = erfc(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('erfc', x); 44 | end 45 | 46 | 47 | %!error erfc (sym(1), 2) 48 | %!assert (isequaln (erfc (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = erfc(x); 56 | %! f2 = erfc(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = erfc(A); 63 | %! f2 = erfc(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = erfc (d); 70 | %! f = erfc (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/expand.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym expand (@var{f}) 22 | %% Combine parts of a symbolic product. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% expand ((x+1)*(x+5)) 29 | %% @result{} (sym) 30 | %% 2 31 | %% x + 6⋅x + 5 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/factor} 36 | %% @end defmethod 37 | 38 | 39 | function y = expand(x) 40 | 41 | y = pycall_sympy__ ( 'return sympy.expand(*_ins),', sym(x)); 42 | 43 | end 44 | 45 | 46 | %!test 47 | %! syms x 48 | %! assert (logical (x^2 + 6*x + 5 == expand ((x+5)*(x+1)))) 49 | %! assert (isequal (x^2 + 6*x + 5, expand ((x+5)*(x+1)))) 50 | 51 | %!test 52 | %! % array 53 | %! syms x 54 | %! assert (isequal (expand ([x (x+1)*x]), [x x^2+x])) 55 | -------------------------------------------------------------------------------- /inst/@sym/fix.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym fix (@var{x}) 22 | %% Symbolic fix function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% y = fix(sym(3)/2) 28 | %% @result{} y = (sym) 1 29 | %% @end group 30 | %% @end example 31 | %% 32 | %% @seealso{@@sym/ceil, @@sym/floor, @@sym/frac, @@sym/round} 33 | %% @end defmethod 34 | 35 | 36 | function y = fix(x) 37 | if (nargin ~= 1) 38 | print_usage (); 39 | end 40 | y = elementwise_op ('Integer', x); 41 | end 42 | 43 | 44 | %!test 45 | %! d = 3/2; 46 | %! x = sym('3/2'); 47 | %! f1 = fix(x); 48 | %! f2 = fix(d); 49 | %! assert (isequal (f1, f2)) 50 | 51 | %!test 52 | %! D = [1.1 4.6; -3.4 -8.9]; 53 | %! A = [sym(11)/10 sym(46)/10; sym(-34)/10 sym(-89)/10]; 54 | %! f1 = fix(A); 55 | %! f2 = fix(D); 56 | %! assert( isequal (f1, f2)) 57 | 58 | %!test 59 | %! d = sym(-11)/10; 60 | %! c = -1; 61 | %! assert (isequal (fix (d), c)) 62 | 63 | %!test 64 | %! d = sym(-19)/10; 65 | %! c = -1; 66 | %! assert (isequal (fix (d), c)) 67 | -------------------------------------------------------------------------------- /inst/@sym/fliplr.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym fliplr (@var{A}) 22 | %% Flip a symbolic matrix horizontally. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = sym([1 2 pi; 4 5 6]); 28 | %% fliplr (A) 29 | %% @result{} (sym 2×3 matrix) 30 | %% ⎡π 2 1⎤ 31 | %% ⎢ ⎥ 32 | %% ⎣6 5 4⎦ 33 | %% @end group 34 | %% @end example 35 | %% 36 | %% @seealso{@@sym/flipud, @@sym/reshape} 37 | %% @end defmethod 38 | 39 | 40 | function B = fliplr (A) 41 | 42 | cmd = { 'A, = _ins' 43 | 'if A is None or not A.is_Matrix:' 44 | ' A = sp.Matrix([A])' 45 | 'return A[:, ::-1]' }; 46 | 47 | B = pycall_sympy__ (cmd, sym(A)); 48 | 49 | end 50 | 51 | 52 | %!test 53 | %! % simple 54 | %! syms x 55 | %! A = [x 2; sym(pi) x]; 56 | %! B = [2 x; x sym(pi)]; 57 | %! assert (isequal (fliplr(A), B)) 58 | 59 | %!test 60 | %! % simple, odd # cols 61 | %! syms x 62 | %! A = [x 2 sym(pi); x 1 2]; 63 | %! B = [sym(pi) 2 x; 2 1 x]; 64 | %! assert (isequal (fliplr(A), B)) 65 | 66 | %!test 67 | %! % scalar 68 | %! syms x 69 | %! assert (isequal (fliplr(x), x)) 70 | -------------------------------------------------------------------------------- /inst/@sym/flipud.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym flipud (@var{A}) 22 | %% Flip a symbolic matrix vertically. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = sym([1 2 pi; 4 5 6]); 28 | %% flipud (A) 29 | %% @result{} (sym 2×3 matrix) 30 | %% ⎡4 5 6⎤ 31 | %% ⎢ ⎥ 32 | %% ⎣1 2 π⎦ 33 | %% @end group 34 | %% @end example 35 | %% 36 | %% @seealso{@@sym/fliplr, @@sym/reshape} 37 | %% @end defmethod 38 | 39 | 40 | function B = flipud (A) 41 | 42 | cmd = { 'A, = _ins' 43 | 'if A is None or not A.is_Matrix:' 44 | ' A = sp.Matrix([A])' 45 | 'return A[::-1, :]' }; 46 | 47 | B = pycall_sympy__ (cmd, sym(A)); 48 | 49 | end 50 | 51 | 52 | %!test 53 | %! % simple 54 | %! syms x 55 | %! A = [x 2; sym(pi) x]; 56 | %! B = [sym(pi) x; x 2]; 57 | %! assert (isequal (flipud(A), B)) 58 | 59 | %!test 60 | %! % simple, odd # rows 61 | %! syms x 62 | %! A = [x 2; sym(pi) x; [1 2]]; 63 | %! B = [[1 2]; sym(pi) x; x 2]; 64 | %! assert (isequal (flipud(A), B)) 65 | 66 | %!test 67 | %! % scalar 68 | %! syms x 69 | %! assert (isequal (flipud(x), x)) 70 | -------------------------------------------------------------------------------- /inst/@sym/formula.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym formula (@var{f}) 22 | %% Return a symbolic expression for this object. 23 | %% 24 | %% For a @@sym, this simply returns the sym itself. Subclasses 25 | %% such as @@symfun may do more interesting things. 26 | %% 27 | %% Example: 28 | %% @example 29 | %% @group 30 | %% syms x 31 | %% f = 2*x; 32 | %% formula(f) 33 | %% @result{} ans = (sym) 2⋅x 34 | %% @end group 35 | %% @end example 36 | %% 37 | %% @seealso{@@symfun/formula, argnames, @@sym/argnames} 38 | %% @end defmethod 39 | 40 | 41 | function g = formula(f) 42 | g = f; 43 | end 44 | 45 | 46 | %!test 47 | %! syms x 48 | %! assert (isequal (formula(x), x)) 49 | %! assert (isequal (formula(2*x), 2*x)) 50 | -------------------------------------------------------------------------------- /inst/@sym/frac.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% Copyright (C) 2016 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @documentencoding UTF-8 22 | %% @defmethod @@sym frac (@var{x}) 23 | %% Return the fractional part of a symbolic expression. 24 | %% 25 | %% Examples: 26 | %% @example 27 | %% @group 28 | %% y = frac(sym(3)/2) 29 | %% @result{} y = (sym) 1/2 30 | %% 31 | %% syms x 32 | %% rewrite(frac(x), 'floor') 33 | %% @result{} ans = (sym) x - ⌊x⌋ 34 | %% @end group 35 | %% @end example 36 | %% 37 | %% @seealso{@@sym/ceil, @@sym/floor, @@sym/fix, @@sym/round} 38 | %% @end defmethod 39 | 40 | 41 | function y = frac(x) 42 | if (nargin ~= 1) 43 | print_usage (); 44 | end 45 | y = elementwise_op ('frac', x); 46 | end 47 | 48 | 49 | %!test 50 | %! f1 = frac(sym(11)/10); 51 | %! f2 = sym(1)/10; 52 | %! assert (isequal (f1, f2)) 53 | 54 | %!test 55 | %! d = sym(-11)/10; 56 | %! c = sym(9)/10; 57 | %! assert (isequal (frac (d), c)) 58 | 59 | %!test 60 | %! d = sym(-19)/10; 61 | %! c = sym(1)/10; 62 | %! assert (isequal (frac (d), c)) 63 | -------------------------------------------------------------------------------- /inst/@sym/hilb.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% Copyright (C) 2019 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @documentencoding UTF-8 22 | %% @defmethod @@sym hilb (@var{n}) 23 | %% Return the symbolic Hilbert matrix. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% hilb (sym(2)) 29 | %% @result{} ans = (sym 2×2 matrix) 30 | %% ⎡ 1 1/2⎤ 31 | %% ⎢ ⎥ 32 | %% ⎣1/2 1/3⎦ 33 | %% @end group 34 | %% @end example 35 | %% 36 | %% @seealso{@@sym/invhilb} 37 | %% @end defmethod 38 | 39 | 40 | function y = hilb(x) 41 | if (nargin ~= 1) 42 | print_usage (); 43 | end 44 | 45 | y = pycall_sympy__ ('return Matrix(_ins[0], _ins[0], lambda i,j: 1 / (i + j + 1)),', x); 46 | 47 | end 48 | 49 | 50 | %!test 51 | %! A = hilb (sym(3)); 52 | %! B = [sym(1) sym(1)/2 sym(1)/3; sym(1)/2 sym(1)/3 sym(1)/4; sym(1)/3 sym(1)/4 sym(1)/5]; 53 | %! assert (isequal (A, B)) 54 | -------------------------------------------------------------------------------- /inst/@sym/invhilb.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym invhilb (@var{n}) 22 | %% Return the symbolic inverse of the Hilbert matrix. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% invhilb (sym(2)) 28 | %% @result{} ans = (sym 2×2 matrix) 29 | %% ⎡4 -6⎤ 30 | %% ⎢ ⎥ 31 | %% ⎣-6 12⎦ 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/hilb} 36 | %% @end defmethod 37 | 38 | 39 | function y = invhilb(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | 44 | y = inv(hilb(x)); 45 | 46 | end 47 | 48 | 49 | %!test 50 | %! A = invhilb(sym(3)); 51 | %! B = sym([9 -36 30;-36 192 -180;30 -180 180]); 52 | %! assert( isequal( A, B)) 53 | -------------------------------------------------------------------------------- /inst/@sym/ipermute.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015, 2016, 2018, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym ipermute (@var{B}, @var{iperm}) 22 | %% Invert a permutation the indices of a symbolic array. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = sym([1 2 pi; 4 5 6]); 28 | %% B = permute(A, [2 1]); 29 | %% ipermute(B, [2 1]) 30 | %% @result{} ans = (sym 2×3 matrix) 31 | %% ⎡1 2 π⎤ 32 | %% ⎢ ⎥ 33 | %% ⎣4 5 6⎦ 34 | %% @end group 35 | %% @end example 36 | %% 37 | %% @seealso{@@sym/permute} 38 | %% @end defmethod 39 | 40 | 41 | function A = ipermute(B, iperm) 42 | 43 | if (nargin < 2) 44 | print_usage (); 45 | end 46 | 47 | A = permute(B, iperm); 48 | 49 | end 50 | 51 | 52 | %!error permute (sym(1)) 53 | %!error permute (sym(1), 2, 3) 54 | 55 | %!test 56 | %! syms x 57 | %! A = [1 x]; 58 | %! perm = [2 1]; 59 | %! B = permute(A, perm); 60 | %! C = ipermute(B, perm); 61 | %! assert (isequal(C, A)) 62 | -------------------------------------------------------------------------------- /inst/@sym/isallconstant.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym isallconstant (@var{x}) 22 | %% Whether all elements of a symbolic array are constant. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = [1 2 sym(pi); sym(4) 5 6] 28 | %% @result{} A = (sym 2×3 matrix) 29 | %% ⎡1 2 π⎤ 30 | %% ⎢ ⎥ 31 | %% ⎣4 5 6⎦ 32 | %% 33 | %% isallconstant (A) 34 | %% @result{} ans = 1 35 | %% @end group 36 | %% 37 | %% @group 38 | %% A(1) = sym('x') 39 | %% @result{} A = (sym 2×3 matrix) 40 | %% ⎡x 2 π⎤ 41 | %% ⎢ ⎥ 42 | %% ⎣4 5 6⎦ 43 | %% 44 | %% isallconstant (A) 45 | %% @result{} ans = 0 46 | %% @end group 47 | %% @end example 48 | %% 49 | %% @seealso{@@sym/isconstant, @@sym/symvar, findsymbols} 50 | %% @end defmethod 51 | 52 | 53 | function z = isallconstant(x) 54 | 55 | z = isempty (findsymbols (x)); 56 | 57 | end 58 | 59 | 60 | %!assert (isallconstant([sym(1) 2 3])) 61 | 62 | %!test 63 | %! syms x 64 | %! assert (~isallconstant([sym(1) x 3])) 65 | 66 | %!test 67 | %! syms x 68 | %! assert (~isallconstant([sym(1) x; sym(2) 3])) 69 | -------------------------------------------------------------------------------- /inst/@sym/iscolumn.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym iscolumn (@var{x}) 22 | %% Return true if symbolic expression is a column vector. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% v = sym([1; 2; 3]); 28 | %% iscolumn(v) 29 | %% @result{} 1 30 | %% iscolumn(sym(1)) 31 | %% @result{} 1 32 | %% iscolumn(v') 33 | %% @result{} 0 34 | %% @end group 35 | %% @end example 36 | %% 37 | %% @seealso{@@sym/isrow, @@sym/isvector, @@sym/isscalar} 38 | %% @end defmethod 39 | 40 | 41 | function r = iscolumn(x) 42 | 43 | if (nargin ~= 1) 44 | print_usage (); 45 | end 46 | 47 | % from Rik Wehbring's Octave function: 48 | sz = size (x); 49 | r = (ndims (x) == 2 && (sz(2) == 1)); 50 | 51 | end 52 | 53 | 54 | %!assert (iscolumn (sym ([1]))) 55 | %!assert (iscolumn (sym ([1 2 3]'))) 56 | %!assert (~iscolumn (sym ([]))) 57 | %!assert (~iscolumn (sym ([1 2 3]))) 58 | %!assert (~iscolumn (sym ([1 2; 3 4]))) 59 | -------------------------------------------------------------------------------- /inst/@sym/ismatrix.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym ismatrix (@var{x}) 22 | %% Return true if this symbolic expression is a matrix. 23 | %% 24 | %% This returns true for all 2D arrays including matrices, scalars, 25 | %% vectors and empty matrices. This function is provided mostly for 26 | %% compatibility with double arrays: it would return false for 3D 27 | %% arrays; however 3D symbolic arrays are not currently supported. 28 | %% 29 | %% Example: 30 | %% @example 31 | %% @group 32 | %% A = sym([1 2; 3 4]); 33 | %% ismatrix(A) 34 | %% @result{} 1 35 | %% ismatrix(sym([1 2 3])) 36 | %% @result{} 1 37 | %% @end group 38 | %% @end example 39 | %% 40 | %% @seealso{@@sym/isscalar, @@sym/isvector, @@sym/size} 41 | %% @end defmethod 42 | 43 | 44 | function b = ismatrix(x) 45 | 46 | b = (length(size(x)) == 2); 47 | 48 | end 49 | 50 | 51 | %!assert(ismatrix(sym('x'))) 52 | %!assert(ismatrix(sym([1 2 3]))) 53 | %!assert(ismatrix(sym([1; 2]))) 54 | %!assert(ismatrix(sym([1 2; 3 4]))) 55 | %!assert(ismatrix(sym([]))) 56 | %!assert(ismatrix(sym(ones(1,0)))) 57 | %!assert(ismatrix(sym(ones(0,3)))) 58 | -------------------------------------------------------------------------------- /inst/@sym/isna.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym isna (@var{x}) 22 | %% Symbolic expressions cannot be the Octave/R missing data NA. 23 | %% 24 | %% Always returns false: 25 | %% @example 26 | %% @group 27 | %% isna([sym(1) sym('x') sym(nan)]) 28 | %% @result{} ans = 29 | %% 0 0 0 30 | %% @end group 31 | %% @end example 32 | %% (We have this mainly so @code{assert} works properly.) 33 | %% 34 | %% @seealso{@@sym/isnan} 35 | %% @end defmethod 36 | 37 | 38 | function r = isna(x) 39 | 40 | r = logical(zeros(size(x))); 41 | 42 | end 43 | 44 | 45 | %!test 46 | %! % no sym should be NA 47 | %! syms x oo 48 | %! assert (~isna(sym(1))) 49 | %! assert (~isna(x)) 50 | %! assert (~isna(oo)) 51 | %! assert (~isna(sym(nan))) 52 | %! assert (isequal (isna (sym ([1 nan])), [false false])) 53 | -------------------------------------------------------------------------------- /inst/@sym/isrow.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym isrow (@var{x}) 22 | %% Return true if symbolic expression is a row vector. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% h = sym([1 2 3]); 28 | %% isrow(h) 29 | %% @result{} 1 30 | %% isrow(sym(1)) 31 | %% @result{} 1 32 | %% isrow(h') 33 | %% @result{} 0 34 | %% @end group 35 | %% @end example 36 | %% 37 | %% @seealso{@@sym/iscolumn, @@sym/isvector, @@sym/isscalar} 38 | %% @end defmethod 39 | 40 | 41 | function r = isrow(x) 42 | 43 | if (nargin ~= 1) 44 | print_usage (); 45 | end 46 | 47 | % from Rik Wehbring's Octave function 48 | sz = size (x); 49 | r = (ndims (x) == 2 && (sz(1) == 1)); 50 | 51 | end 52 | 53 | 54 | %!assert (isrow (sym ([1]))) 55 | %!assert (isrow (sym ([1 2 3]))) 56 | %!assert (~isrow (sym ([]))) 57 | %!assert (~isrow (sym ([1 2 3]'))) 58 | %!assert (~isrow (sym ([1 2; 3 4]))) 59 | -------------------------------------------------------------------------------- /inst/@sym/isscalar.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym isscalar (@var{x}) 22 | %% Return true if this symbolic expression is a scalar. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% s = sym(1); 28 | %% v = sym([1 2 3]); 29 | %% isscalar(s) 30 | %% @result{} 1 31 | %% isscalar(v) 32 | %% @result{} 0 33 | %% @end group 34 | %% @end example 35 | %% 36 | %% @seealso{@@sym/size, @@sym/numel, @@sym/isvector} 37 | %% @end defmethod 38 | 39 | 40 | function b = isscalar(x) 41 | 42 | if (nargin ~= 1) 43 | print_usage (); 44 | end 45 | 46 | d = size(x); 47 | n = prod(d); 48 | b = (n == 1); 49 | 50 | end 51 | 52 | 53 | %!assert(isscalar(sym('x'))) 54 | 55 | %!test 56 | %! a = sym([1 2 3]); 57 | %! assert(~isscalar(a)) 58 | 59 | %!assert(~isscalar(sym([]))) 60 | -------------------------------------------------------------------------------- /inst/@sym/isvector.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym isvector (@var{x}) 22 | %% Return true if this symbolic expression is a vector. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = sym([1 2; 3 4]); 28 | %% v = sym([1 2 3]); 29 | %% h = v'; 30 | %% isvector(A) 31 | %% @result{} 0 32 | %% isvector(v) 33 | %% @result{} 1 34 | %% isvector(h) 35 | %% @result{} 1 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/size, @@sym/numel, @@sym/isscalar} 40 | %% @end defmethod 41 | 42 | 43 | function b = isvector(x) 44 | 45 | if (nargin ~= 1) 46 | print_usage (); 47 | end 48 | 49 | d = size(x); 50 | b = any(d == 1); 51 | 52 | end 53 | 54 | 55 | %!assert(isvector(sym('x'))) 56 | %!assert(isvector(sym([1 2 3]))) 57 | %!assert(isvector(sym([1; 2]))) 58 | %!assert(~isvector(sym([1 2; 3 4]))) 59 | %!assert(~isvector(sym([]))) 60 | %!assert(isvector(sym(ones(1,0)))) 61 | %!assert(~isvector(sym(ones(0,3)))) 62 | -------------------------------------------------------------------------------- /inst/@sym/latex.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016, 2019, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @deftypemethod @@sym {} latex (@var{x}) 22 | %% @deftypemethodx @@sym {@var{s} =} latex (@var{x}) 23 | %% Display or return LaTeX typesetting code for symbolic expression. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% latex(sin(x/2)) 30 | %% @print{} \sin@{\left(\frac@{x@}@{2@} \right)@} 31 | %% @end group 32 | %% 33 | %% @group 34 | %% A = [sym(1) 2; sym(3) 4]; 35 | %% s = latex(A) 36 | %% @result{} s = \left[\begin@{matrix@}1 & 2\\3 & 4\end@{matrix@}\right] 37 | %% @end group 38 | %% @end example 39 | %% 40 | %% @seealso{@@sym/disp, @@sym/pretty} 41 | %% @end deftypemethod 42 | 43 | 44 | function varargout = latex(x) 45 | 46 | if (nargin ~= 1) 47 | print_usage (); 48 | end 49 | 50 | cmd = { 'return sp.latex(*_ins),' }; 51 | 52 | s = pycall_sympy__ (cmd, x); 53 | 54 | if (nargout == 0) 55 | disp(s) 56 | else 57 | varargout = {s}; 58 | end 59 | 60 | end 61 | 62 | 63 | %!test 64 | %! syms x 65 | %! y = sin(x); 66 | %! assert (strcmp (latex (y), '\sin{\left(x \right)}')) 67 | 68 | %!assert (strcmp (latex (exp (sym('x'))), 'e^{x}')) 69 | -------------------------------------------------------------------------------- /inst/@sym/length.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym length (@var{x}) 22 | %% Length of a symbolic vector. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% A = [1 2 x; x 3 4]; 29 | %% length(A) 30 | %% @result{} 3 31 | %% @end group 32 | %% @end example 33 | %% 34 | %% As usual, be careful with this and matrices: you may want 35 | %% @code{numel} instead. 36 | %% 37 | %% @seealso{@@sym/numel, @@sym/size} 38 | %% @end defmethod 39 | 40 | function n = length(x) 41 | 42 | d = size(x); 43 | n = max(d); 44 | 45 | end 46 | 47 | 48 | %!test 49 | %! a = sym([1 2 3]); 50 | %! assert(length(a) == 3); 51 | 52 | %!test 53 | %! % 2D array 54 | %! a = sym([1 2 3; 4 5 6]); 55 | %! assert(length(a) == 3); 56 | 57 | %!test 58 | %! % empty 59 | %! a = sym([]); 60 | %! assert(length(a) == 0); 61 | -------------------------------------------------------------------------------- /inst/@sym/lgamma.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym gammaln (@var{x}) 22 | %% @defmethodx @@sym lgamma (@var{x}) 23 | %% Symbolic logarithm of the gamma function. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% y = gammaln(x) 30 | %% @result{} y = (sym) loggamma(x) 31 | %% y = lgamma(x) 32 | %% @result{} y = (sym) loggamma(x) 33 | %% @end group 34 | %% @end example 35 | %% 36 | %% @seealso{gammaln, @@sym/gamma, @@sym/psi} 37 | %% @end defmethod 38 | 39 | function y = lgamma(x) 40 | y = gammaln(x); 41 | end 42 | 43 | 44 | %!test 45 | %! % tested by gammaln 46 | %! assert (isequal (lgamma (sym ('x')), gammaln (sym ('x')))) 47 | -------------------------------------------------------------------------------- /inst/@sym/log.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym log (@var{x}) 22 | %% Symbolic log function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = log (x) 29 | %% @result{} y = (sym) log(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = log(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('log', x); 44 | end 45 | 46 | 47 | %!error log (sym(1), 2) 48 | %!assert (isequaln (log (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = log(x); 56 | %! f2 = log(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = log(A); 63 | %! f2 = log(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = log (d); 70 | %! f = log (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/log10.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym log10 (@var{x}) 22 | %% Symbolic log base 10 function. 23 | %% 24 | %% Examples: 25 | %% @example 26 | %% @group 27 | %% log10(sym(1000)) 28 | %% @result{} ans = (sym) 3 29 | %% 30 | %% syms x 31 | %% log10(x) 32 | %% @result{} ans = (sym) 33 | %% log(x) 34 | %% ─────── 35 | %% log(10) 36 | %% @end group 37 | %% @end example 38 | %% @seealso{@@sym/log, @@sym/log2} 39 | %% @end defmethod 40 | 41 | 42 | function z = log10(x) 43 | 44 | z = elementwise_op ('lambda x: sp.log(x, 10)', x); 45 | 46 | end 47 | 48 | 49 | %!assert (isequal (log10 (sym (1000)), sym (3))) 50 | 51 | %!assert (isequal (log10 (sym ([10 100])), sym ([1 2]))) 52 | 53 | %!test 54 | %! % round-trip 55 | %! syms x 56 | %! f = log10 (x); 57 | %! h = function_handle (f); 58 | %! A = h (1.1); 59 | %! B = log10 (1.1); 60 | %! assert (A, B, -eps) 61 | -------------------------------------------------------------------------------- /inst/@sym/log2.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym log2 (@var{x}) 22 | %% Symbolic log base 2 function. 23 | %% 24 | %% Examples: 25 | %% @example 26 | %% @group 27 | %% log2(sym(256)) 28 | %% @result{} ans = (sym) 8 29 | %% 30 | %% syms x 31 | %% log2(x) 32 | %% @result{} ans = (sym) 33 | %% log(x) 34 | %% ────── 35 | %% log(2) 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/log, @@sym/log10} 40 | %% @end defmethod 41 | 42 | 43 | function z = log2(x) 44 | 45 | z = elementwise_op ('lambda x: sp.log(x, 2)', x); 46 | 47 | end 48 | 49 | 50 | %!assert (isequal (log2 (sym (1024)), sym (10))) 51 | 52 | %!assert (isequal (log2 (sym ([2 16; 32 1])), sym ([1 4; 5 0]))) 53 | 54 | %!test 55 | %! % round-trip 56 | %! syms x 57 | %! f = log2 (x); 58 | %! h = function_handle (f); 59 | %! A = h (1.1); 60 | %! B = log2 (1.1); 61 | %! assert (A, B, -5*eps) 62 | -------------------------------------------------------------------------------- /inst/@sym/matlabFunction.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym matlabFunction (@var{f}) 22 | %% Convert symbolic expression into a standard function. 23 | %% 24 | %% This is a synonym of @code{function_handle}. For further 25 | %% documentation, @pxref{@@sym/function_handle} 26 | %% 27 | %% @seealso{@@sym/function_handle} 28 | %% 29 | %% @end defmethod 30 | 31 | 32 | function f = matlabFunction(varargin) 33 | 34 | f = function_handle(varargin{:}); 35 | 36 | end 37 | 38 | 39 | %!test 40 | %! % autodetect inputs 41 | %! syms x y 42 | %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); 43 | %! h = matlabFunction(2*x*y, x+y); 44 | %! warning(s) 45 | %! [t1, t2] = h(3,5); 46 | %! assert(t1 == 30 && t2 == 8) 47 | -------------------------------------------------------------------------------- /inst/@sym/nextprime.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym nextprime (@var{x}) 22 | %% Return the next prime number. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% nextprime(sym(2)) 28 | %% @result{} ans = (sym) 3 29 | % 30 | %% nextprime([sym(2) 10 0 -1 65530]) 31 | %% @result{} (sym) [3 11 2 2 65537] (1×5 matrix) 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/isprime, @@sym/prevprime} 36 | %% @end defmethod 37 | 38 | 39 | function y = nextprime(x) 40 | 41 | %y = elementwise_op ('nextprime', x); 42 | 43 | % workaround as upstream SymPy returns int, not sym 44 | y = elementwise_op ('lambda a: S(nextprime(a))', x); 45 | 46 | end 47 | 48 | 49 | %!assert (isequal (nextprime(sym(2)), 3)); 50 | %!assert (isequal (nextprime(sym(18)), 19)); 51 | %!assert (isequal (nextprime(sym([1 2 3])), [2 3 5])); 52 | 53 | %!assert (isequal (nextprime(sym([-1 0])), [2 2])); 54 | 55 | %!test 56 | %! % result is a sym 57 | %! p = nextprime(sym(2)); 58 | %! assert (isa (p, 'sym')) 59 | -------------------------------------------------------------------------------- /inst/@sym/numel.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym numel (@var{x}) 22 | %% Return number of elements in symbolic array. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% A = [1 2 x; x 3 4]; 29 | %% numel(A) 30 | %% @result{} 6 31 | %% @end group 32 | %% @end example 33 | %% 34 | %% @seealso{@@sym/length, @@sym/size} 35 | %% @end defmethod 36 | 37 | function n = numel(x) 38 | 39 | %disp('numel call') 40 | d = size(x); 41 | n = prod(d); 42 | 43 | end 44 | 45 | 46 | %!test 47 | %! a = sym([1 2 3]); 48 | %! assert(numel(a) == 3); 49 | 50 | %!test 51 | %! % 2D array 52 | %! a = sym([1 2 3; 4 5 6]); 53 | %! assert(numel(a) == 6); 54 | 55 | %!test 56 | %! % empty 57 | %! a = sym([]); 58 | %! assert(numel(a) == 0); 59 | -------------------------------------------------------------------------------- /inst/@sym/pinv.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym pinv (@var{A}) 22 | %% Symbolic Moore-Penrose pseudoinverse of a matrix. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = sym([1 2; 3 4; 5 6]) 28 | %% @result{} A = (sym 3×2 matrix) 29 | %% ⎡1 2⎤ 30 | %% ⎢ ⎥ 31 | %% ⎢3 4⎥ 32 | %% ⎢ ⎥ 33 | %% ⎣5 6⎦ 34 | %% 35 | %% pinv(A) 36 | %% @result{} (sym 2×3 matrix) 37 | %% ⎡-4/3 -1/3 2/3 ⎤ 38 | %% ⎢ ⎥ 39 | %% ⎢ 13 ⎥ 40 | %% ⎢ ── 1/3 -5/12⎥ 41 | %% ⎣ 12 ⎦ 42 | %% @end group 43 | %% @end example 44 | %% @end defmethod 45 | 46 | 47 | function z = pinv(x) 48 | 49 | cmd = { 'x, = _ins' 50 | 'if not x.is_Matrix:' 51 | ' x = sp.Matrix([[x]])' 52 | 'return x.pinv(),' }; 53 | 54 | z = pycall_sympy__ (cmd, x); 55 | 56 | end 57 | 58 | 59 | %!test 60 | %! % scalar 61 | %! syms x 62 | %! assert (isequal (pinv(x), 1/x)) 63 | 64 | %!test 65 | %! % 2x3 66 | %! A = [1 2 3; 4 5 6]; 67 | %! assert (max (max (abs (double (pinv (sym (A))) - pinv(A)))) <= 10*eps) 68 | -------------------------------------------------------------------------------- /inst/@sym/prevprime.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2017 NVS Abhilash 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym prevprime (@var{x}) 22 | %% Return the previous prime number. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% prevprime(sym(3)) 28 | %% @result{} ans = (sym) 2 29 | % 30 | %% prevprime([sym(3) 10 100 1000 65530]) 31 | %% @result{} (sym) [2 7 97 997 65521] (1×5 matrix) 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/isprime, @@sym/nextprime} 36 | %% @end defmethod 37 | 38 | 39 | function y = prevprime(x) 40 | 41 | if (nargin ~= 1) 42 | print_usage () 43 | end 44 | 45 | %y = elementwise_op ('prevprime', x); 46 | 47 | % workaround as upstream SymPy returns int, not sym 48 | y = elementwise_op ('lambda a: S(prevprime(a))', x); 49 | 50 | end 51 | 52 | 53 | %!assert (isequal (prevprime(sym(3)), 2)); 54 | %!assert (isequal (prevprime(sym(20)), 19)); 55 | %!assert (isequal (prevprime(sym([3 5 10])), [2 3 7])); 56 | 57 | %!error prevprime(sym(2)) 58 | %!error prevprime(sym(-2)) 59 | 60 | %!test 61 | %! % result is a sym 62 | %! p = prevprime(sym(3)); 63 | %! assert (isa (p, 'sym')) 64 | -------------------------------------------------------------------------------- /inst/@sym/private/assert_same_shape.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function t = assert_same_shape(x,y) 20 | if ~(is_same_shape(x,y)) 21 | error('array inputs must have same size and shape'); 22 | end 23 | 24 | -------------------------------------------------------------------------------- /inst/@sym/private/cell2nosyms.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function z = cell2nosyms(x) 20 | 21 | for i=1:length(x) 22 | if isa(x{i}, 'sym') 23 | x{i} = double(x{i}); 24 | end 25 | end 26 | 27 | z = x; 28 | 29 | end 30 | -------------------------------------------------------------------------------- /inst/@sym/private/check_assumptions.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @deftypefun check_assumptions (@var{x}) 21 | %% Check if the input have valid assumptions. 22 | %% 23 | %% Private helper function. 24 | %% 25 | %% @seealso{sym} 26 | %% @end deftypefun 27 | 28 | 29 | function check_assumptions (x) 30 | 31 | ca_helper (x) 32 | 33 | end 34 | 35 | %% Is safer use a helper when private functions call it self for classdef. 36 | function ca_helper (x) 37 | 38 | persistent valid_asm 39 | 40 | if (isempty (valid_asm)) 41 | valid_asm = assumptions ('possible'); 42 | end 43 | 44 | if (~islogical (x)) 45 | if (isa (x, 'char')) 46 | assert (ismember (x, valid_asm), ['sym: the assumption "' x '" is not supported in your Sympy version.']) 47 | elseif (isstruct (x)) 48 | fields = fieldnames (x); 49 | for j = 1:numel (fields) 50 | ca_helper (fields{j}) 51 | end 52 | elseif (iscell (x)) 53 | for j = 1:length (x) 54 | ca_helper (x{j}) 55 | end 56 | else 57 | error ('sym: assumption must be a string or struct or cell') 58 | end 59 | end 60 | 61 | end 62 | -------------------------------------------------------------------------------- /inst/@sym/private/double_to_sym_exact.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2017, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @deftypefun {@var{y} =} double_to_sym_exact (@var{x}) 21 | %% Convert a double value to the equivalent rational sym 22 | %% 23 | %% Private helper function. 24 | %% 25 | %% @end deftypefun 26 | 27 | function y = double_to_sym_exact (x) 28 | if (isnan (x)) 29 | y = pycall_sympy__ ('return S.NaN'); 30 | elseif (isinf (x) && x < 0) 31 | y = pycall_sympy__ ('return -S.Infinity'); 32 | elseif (isinf (x)) 33 | y = pycall_sympy__ ('return S.Infinity'); 34 | else 35 | %% Rational will exactly convert from a float 36 | y = pycall_sympy__ ('return Rational(_ins[0])', x); 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /inst/@sym/private/ineq_helper.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function t = ineq_helper(op, fop, lhs, rhs, nanspecial) 20 | 21 | if (nargin == 4) 22 | nanspecial = 'S.false'; 23 | end 24 | 25 | % FIXME: this will need to catch exceptions soon 26 | op = { 'def _op(lhs, rhs):' 27 | ' # workaround sympy nan behaviour, Issue #9' 28 | ' if lhs is nan or rhs is nan:' 29 | [' return ' nanspecial] 30 | [' return ' fop '(lhs, rhs)'] }; 31 | 32 | t = elementwise_op (op, lhs, rhs); 33 | 34 | end 35 | 36 | -------------------------------------------------------------------------------- /inst/@sym/private/is_same_shape.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function t = is_same_shape(x,y) 20 | %IS_SAME_SHAPE Inputs have same shape 21 | % Note does not say same type 22 | 23 | d1 = size(x); 24 | d2 = size(y); 25 | t = ( ... 26 | (length(d1) == length(d2)) && ... 27 | (all(d1 == d2)) ... 28 | ); 29 | 30 | -------------------------------------------------------------------------------- /inst/@sym/private/is_valid_index.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defun is_valid_index (@var{x}) 22 | %% Could the input in principle be used as an index. 23 | %% 24 | %% Note it doesn't check that its valid for any particular 25 | %% indexing operation, just that its not too crazy (e.g., 26 | %% a non-integer). 27 | %% 28 | %% Specific things that are valid: 29 | %% @itemize 30 | %% @item strings @qcode{':'} and @qcode{'@w{}'} 31 | %% @item empties such as @qcode{[]} 32 | %% @item boolean 33 | %% @item finite real integers 34 | %% @end itemize 35 | %% @end defun 36 | 37 | function r = is_valid_index(x) 38 | 39 | if (ischar (x)) 40 | r = strcmp (x, ':') || strcmp (x, ''); 41 | return 42 | end 43 | 44 | if (isempty (x)) 45 | r = true; 46 | return 47 | end 48 | 49 | if (islogical (x)) 50 | r = true; 51 | return 52 | end 53 | 54 | % check that all are integers 55 | x = x(:); 56 | r = all (isreal (x) & isfinite (x) & (x == floor(x))); 57 | 58 | end 59 | -------------------------------------------------------------------------------- /inst/@sym/private/mat_rclist_access.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @defun mat_rclist_access (@var{A}, @var{r}, @var{c}) 21 | %% Private helper routine for sym array access via lists of row/col. 22 | %% 23 | %% @code{(r(i),c(i))} specify entries of the matrix @var{A}. 24 | %% Returns a column vector of these extracted from @var{A}. 25 | %% 26 | %% @end defun 27 | 28 | 29 | function z = mat_rclist_access(A, r, c) 30 | 31 | if ~( isvector(r) && isvector(c) && (length(r) == length(c)) ) 32 | error('this routine is for a list of rows and cols'); 33 | end 34 | 35 | cmd = { '(A, rr, cc) = _ins' 36 | 'if A is None or not A.is_Matrix:' 37 | ' A = sp.Matrix([A])' 38 | 'n = len(rr)' 39 | 'M = [[0] for i in range(n)]' 40 | 'for i in range(0, n):' 41 | ' M[i][0] = A[rr[i],cc[i]]' 42 | 'M = sp.Matrix(M)' 43 | 'return M,' }; 44 | 45 | rr = num2cell(int32(r-1)); 46 | cc = num2cell(int32(c-1)); 47 | z = pycall_sympy__ (cmd, A, rr, cc); 48 | end 49 | -------------------------------------------------------------------------------- /inst/@sym/private/numeric_array_to_sym.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2015, 2019, 2023 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function z = numeric_array_to_sym(A, ratflag) 20 | %private helper for sym ctor 21 | % convert an array to syms, currently only 1D, 2D. 22 | 23 | if nargin < 2 24 | ratwarn = true; 25 | else 26 | ratwarn = false; 27 | end 28 | 29 | [n, m] = size(A); 30 | 31 | if (n == 0 || m == 0) 32 | cmd = { sprintf('return sp.Matrix(%d, %d, []),', n, m) }; 33 | z = pycall_sympy__ (cmd); 34 | return 35 | end 36 | 37 | Ac = cell(n,1); 38 | for i=1:n 39 | % we want all sym creation to go through the ctor. 40 | Ac{i} = cell(m,1); 41 | for j=1:m 42 | if ratwarn 43 | Ac{i}{j} = sym (A(i, j)); 44 | else 45 | Ac{i}{j} = sym (A(i, j), ratflag); 46 | end 47 | end 48 | end 49 | 50 | %Ac = {{x 2}; {3 4}; {8 9}}; 51 | 52 | d = size(A); 53 | if (length(d) > 2) 54 | error('conversion not supported for arrays of dim > 2'); 55 | end 56 | 57 | cmd = { 'L = _ins[0]' 58 | 'M = sp.Matrix(L)' 59 | 'return M,' }; 60 | z = pycall_sympy__ (cmd, Ac); 61 | -------------------------------------------------------------------------------- /inst/@sym/private_disp_name.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @defmethod @@sym private_disp_name (@var{x}, @var{name}) 21 | %% A string appropriate for representing the name of this sym. 22 | %% 23 | %% Private method: this is not the method you are looking for. 24 | %% 25 | %% @end defmethod 26 | 27 | function s = private_disp_name(x, input_name) 28 | 29 | s = input_name; 30 | % subclasses might do something more interesting, but they should 31 | % be careful to ensure empty input_name gives empty s. 32 | 33 | end 34 | 35 | 36 | %!test 37 | %! syms x 38 | %! s = private_disp_name(x, 'x'); 39 | %! assert (strcmp (s, 'x')) 40 | -------------------------------------------------------------------------------- /inst/@sym/rank.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym rank (@var{A}) 22 | %% Rank of a symbolic matrix. 23 | %% 24 | %% Examples: 25 | %% @example 26 | %% @group 27 | %% A = sym([1 1; 2 0]); 28 | %% rank (A) 29 | %% @result{} ans = 2 30 | %% @end group 31 | %% 32 | %% @group 33 | %% A = sym([1 2; 1 2]); 34 | %% rank (A) 35 | %% @result{} ans = 1 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/cond, @@sym/null, @@sym/orth} 40 | %% @end defmethod 41 | 42 | 43 | function r = rank(A) 44 | 45 | cmd = { 'A = _ins[0]' 46 | 'if not A.is_Matrix:' 47 | ' A = sp.Matrix([A])' 48 | 'return A.rank(),' }; 49 | 50 | r = pycall_sympy__ (cmd, A); 51 | 52 | end 53 | 54 | 55 | %!test 56 | %! A = sym([1 2; 3 4]); 57 | %! assert (rank(A) == 2); 58 | 59 | %!test 60 | %! A = sym([1 2 3; 3 4 5]); 61 | %! assert (rank(A) == 2); 62 | 63 | %!test 64 | %! A = sym([1 2; 1 2]); 65 | %! assert (rank(A) == 1); 66 | 67 | %!test 68 | %! A = sym([1 2; 3 4]); 69 | %! assert (rank(A) == 2); 70 | 71 | %!assert (rank(sym(1)) == 1); 72 | %!assert (rank(sym(0)) == 0); 73 | %!assert (rank(sym('x', 'positive')) == 1); 74 | -------------------------------------------------------------------------------- /inst/@sym/rhs.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym rhs (@var{f}) 22 | %% Right-hand side of symbolic expression. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% eqn = 5*x <= 3*x + 6 29 | %% @result{} eqn = (sym) 5⋅x ≤ 3⋅x + 6 30 | %% rhs(eqn) 31 | %% @result{} ans = (sym) 3⋅x + 6 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% Gives an error if any of the symbolic objects have no right-hand side. 36 | %% 37 | %% @seealso{@@sym/lhs, @@sym/children, @@sym/formula, @@sym/argnames} 38 | %% @end defmethod 39 | 40 | 41 | function R = rhs(f) 42 | 43 | R = elementwise_op ('lambda a: a.rhs', f); 44 | 45 | end 46 | 47 | 48 | %% most tests are in lhs 49 | %!test 50 | %! syms x 51 | %! f = x + 1 == 2*x; 52 | %! assert (isequal (rhs(f), 2*x)) 53 | 54 | %!error 55 | %! syms x 56 | %! rhs(x) 57 | -------------------------------------------------------------------------------- /inst/@sym/rows.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym rows (@var{x}) 22 | %% Return the number of rows in a symbolic array. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% A = [1 2 sym(pi); 4 5 2*sym(pi)]; 28 | %% n = rows (A) 29 | %% @result{} n = 2 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% @seealso{@@sym/columns, @@sym/size, @@sym/length, @@sym/numel} 34 | %% @end defmethod 35 | 36 | 37 | function n = rows(x) 38 | 39 | n = size(x, 1); 40 | 41 | end 42 | 43 | 44 | %!test 45 | %! a = sym([1 2 3]); 46 | %! assert (rows(a) == 1) 47 | 48 | %!test 49 | %! a = sym([1 2 3; 4 5 6]); 50 | %! assert (rows(a) == 2) 51 | -------------------------------------------------------------------------------- /inst/@sym/sec.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym sec (@var{x}) 22 | %% Symbolic sec function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = sec (x) 29 | %% @result{} y = (sym) sec(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = sec(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('sec', x); 44 | end 45 | 46 | 47 | %!error sec (sym(1), 2) 48 | %!assert (isequaln (sec (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = sec(x); 56 | %! f2 = sec(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = sec(A); 63 | %! f2 = sec(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = sec (d); 70 | %! f = sec (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/sech.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym sech (@var{x}) 22 | %% Symbolic sech function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = sech (x) 29 | %% @result{} y = (sym) sech(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = sech(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('sech', x); 44 | end 45 | 46 | 47 | %!error sech (sym(1), 2) 48 | %!assert (isequaln (sech (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = sech(x); 56 | %! f2 = sech(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = sech(A); 63 | %! f2 = sech(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = sech (d); 70 | %! f = sech (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/sign.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym sign (@var{x}) 22 | %% Symbolic sign function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = sign (x) 29 | %% @result{} y = (sym) sign(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = sign(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('sign', x); 44 | end 45 | 46 | 47 | %!error sign (sym(1), 2) 48 | %!assert (isequaln (sign (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = sign(x); 56 | %! f2 = sign(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = sign(A); 63 | %! f2 = sign(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = sign (d); 70 | %! f = sign (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/sin.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym sin (@var{x}) 22 | %% Symbolic sin function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = sin (x) 29 | %% @result{} y = (sym) sin(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = sin(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('sin', x); 44 | end 45 | 46 | 47 | %!error sin (sym(1), 2) 48 | %!assert (isequaln (sin (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = sin(x); 56 | %! f2 = sin(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = sin(A); 63 | %! f2 = sin(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = sin (d); 70 | %! f = sin (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/sind.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym sind (@var{x}) 22 | %% Symbolic sin function with input in degrees. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% 2*sind (sym (60)) 28 | %% @result{} (sym) √3 29 | %% 30 | %% syms x 31 | %% y = sind (x) 32 | %% @result{} y = (sym) 33 | %% ⎛π⋅x⎞ 34 | %% sin⎜───⎟ 35 | %% ⎝180⎠ 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/asind, @@sym/sin} 40 | %% @end defmethod 41 | 42 | 43 | function y = sind(x) 44 | if (nargin ~= 1) 45 | print_usage (); 46 | end 47 | y = elementwise_op ('lambda a: sin(rad(a))', x); 48 | end 49 | 50 | 51 | %!error sind (sym(1), 2) 52 | %!assert (isequaln (sind (sym(nan)), sym(nan))) 53 | 54 | %!test 55 | %! f1 = sind (sym(1)); 56 | %! f2 = sind (1); 57 | %! assert (double (f1), f2, -eps) 58 | 59 | %!test 60 | %! D = [10 30; 110 -45]; 61 | %! A = sym(D); 62 | %! f1 = sind (A); 63 | %! f2 = sind (D); 64 | %! assert (double (f1), f2, -eps) 65 | -------------------------------------------------------------------------------- /inst/@sym/sinh.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym sinh (@var{x}) 22 | %% Symbolic sinh function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = sinh (x) 29 | %% @result{} y = (sym) sinh(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = sinh(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('sinh', x); 44 | end 45 | 46 | 47 | %!error sinh (sym(1), 2) 48 | %!assert (isequaln (sinh (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = sinh(x); 56 | %! f2 = sinh(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = sinh(A); 63 | %! f2 = sinh(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = sinh (d); 70 | %! f = sinh (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/ssinint.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym ssinint (@var{x}) 22 | %% Symbolic shifted sine integral function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = ssinint(x) 29 | %% @result{} y = (sym) 30 | %% π 31 | %% Si(x) - ─ 32 | %% 2 33 | %% @end group 34 | %% @end example 35 | %% @seealso{@@sym/sinint} 36 | %% @end defmethod 37 | 38 | function y = ssinint(x) 39 | y = elementwise_op ('Si', x) - sym(pi)/2; 40 | end 41 | 42 | 43 | %!assert (isequal (ssinint(sym(0)), -sym(pi)/2)) 44 | 45 | %!test 46 | %! A = ssinint (sym ([0 1])); 47 | %! B = [-pi/2 -0.62471325642771360426]; 48 | %! assert( all(all( abs(double(A)-B) < 1e-15 ))) 49 | -------------------------------------------------------------------------------- /inst/@sym/tan.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym tan (@var{x}) 22 | %% Symbolic tan function. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% syms x 28 | %% y = tan (x) 29 | %% @result{} y = (sym) tan(x) 30 | %% @end group 31 | %% @end example 32 | %% 33 | %% Note: this file is autogenerated: if you want to edit it, you might 34 | %% want to make changes to 'generate_functions.py' instead. 35 | %% 36 | %% @end defmethod 37 | 38 | 39 | function y = tan(x) 40 | if (nargin ~= 1) 41 | print_usage (); 42 | end 43 | y = elementwise_op ('tan', x); 44 | end 45 | 46 | 47 | %!error tan (sym(1), 2) 48 | %!assert (isequaln (tan (sym(nan)), sym(nan))) 49 | 50 | %!shared x, d 51 | %! d = 1; 52 | %! x = sym('1'); 53 | 54 | %!test 55 | %! f1 = tan(x); 56 | %! f2 = tan(d); 57 | %! assert( abs(double(f1) - f2) < 1e-15 ) 58 | 59 | %!test 60 | %! D = [d d; d d]; 61 | %! A = [x x; x x]; 62 | %! f1 = tan(A); 63 | %! f2 = tan(D); 64 | %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) 65 | 66 | %!test 67 | %! % round trip 68 | %! y = sym('y'); 69 | %! A = tan (d); 70 | %! f = tan (y); 71 | %! h = function_handle (f); 72 | %! B = h (d); 73 | %! assert (A, B, -eps) 74 | -------------------------------------------------------------------------------- /inst/@sym/tand.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@sym tand (@var{x}) 22 | %% Symbolic tan function with input in degrees. 23 | %% 24 | %% Example: 25 | %% @example 26 | %% @group 27 | %% tand (sym (60)) 28 | %% @result{} (sym) √3 29 | %% 30 | %% syms x 31 | %% y = tand (x) 32 | %% @result{} y = (sym) 33 | %% ⎛π⋅x⎞ 34 | %% tan⎜───⎟ 35 | %% ⎝180⎠ 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% @seealso{@@sym/atand, @@sym/tan} 40 | %% @end defmethod 41 | 42 | 43 | function y = tand(x) 44 | if (nargin ~= 1) 45 | print_usage (); 46 | end 47 | y = elementwise_op ('lambda a: tan(rad(a))', x); 48 | end 49 | 50 | 51 | %!error tand (sym(1), 2) 52 | %!assert (isequaln (tand (sym(nan)), sym(nan))) 53 | 54 | %!test 55 | %! f1 = tand (sym(1)); 56 | %! f2 = tand (1); 57 | %! assert (double (f1), f2, -eps) 58 | 59 | %!test 60 | %! D = [10 30; 110 -45]; 61 | %! A = sym(D); 62 | %! f1 = tand (A); 63 | %! f2 = tand (D); 64 | %! assert (double (f1), f2, -eps) 65 | -------------------------------------------------------------------------------- /inst/@sym/uminus.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@sym uminus (@var{x}) 22 | %% @defopx Operator @@sym {-@var{x}} {} 23 | %% Return the negation of a symbolic expression. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% -x 30 | %% @result{} (sym) -x 31 | %% -(3 - 2*x) 32 | %% @result{} (sym) 2⋅x - 3 33 | %% @end group 34 | %% @end example 35 | %% @end defop 36 | 37 | 38 | function z = uminus(x) 39 | 40 | z = pycall_sympy__ ('return -_ins[0],', x); 41 | 42 | end 43 | 44 | 45 | %!test 46 | %! % scalar 47 | %! syms x 48 | %! assert (isa (-x, 'sym')) 49 | %! assert (isequal (-(-x), x)) 50 | 51 | %!test 52 | %! % matrix 53 | %! D = [0 1; 2 3]; 54 | %! A = sym(D); 55 | %! assert( isequal( -A, -D )) 56 | -------------------------------------------------------------------------------- /inst/@sym/uplus.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@sym uplus (@var{x}) 22 | %% @defopx Operator @@sym {+@var{x}} {} 23 | %% Symbolic unitary minus. 24 | %% 25 | %% A no-op. Example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% +x 30 | %% @result{} (sym) x 31 | %% @end group 32 | %% @end example 33 | %% @seealso{@@sym/uminus} 34 | %% @end defop 35 | 36 | 37 | function x = uplus(x) 38 | 39 | % no-op 40 | 41 | end 42 | 43 | 44 | %!test 45 | %! syms x 46 | %! assert (isa (+x, 'sym')) 47 | %! assert (isequal (+x, x)) 48 | 49 | %!test 50 | %! A = sym([0 -1 inf]); 51 | %! assert( isequal ( +A, A)) 52 | -------------------------------------------------------------------------------- /inst/@symfun/argnames.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@symfun argnames (@var{f}) 22 | %% Return the independent variables in a symfun. 23 | %% 24 | %% The counterpart of @code{argname} is @code{formula}: 25 | %% @code{argname} for the independent 26 | %% variables and @code{formula} for the dependent expression. 27 | %% 28 | %% Examples: 29 | %% @example 30 | %% @group 31 | %% syms x y 32 | %% f(x, y) = x^2; 33 | %% argnames(f) 34 | %% @result{} (sym) [x y] (1×2 matrix) 35 | %% @end group 36 | %% @end example 37 | %% 38 | %% @seealso{@@symfun/formula, @@symfun/symvar, findsymbols} 39 | %% @end defmethod 40 | 41 | 42 | function vars = argnames(F) 43 | 44 | vars = [F.vars{:}]; 45 | 46 | end 47 | 48 | 49 | %!test 50 | %! % basic test 51 | %! syms f(x) 52 | %! assert (isequal (argnames (f), x)) 53 | 54 | %!test 55 | %! % Multiple variables, abstract symfun 56 | %! syms f(t, x, y) 57 | %! assert (isequal (argnames (f), [t x y])) 58 | 59 | %!test 60 | %! % Concrete symfun 61 | %! syms x y z t 62 | %! f(t, x, y) = x + y + z; 63 | %! assert (isequal (argnames (f), [t x y])) 64 | -------------------------------------------------------------------------------- /inst/@symfun/ldivide.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun ldivide {(@var{f}, @var{g})} 22 | %% @defopx Operator @@symfun {@var{f} .\ @var{g}} {} 23 | %% Component-wise backslash division of symbolic functions. 24 | %% 25 | %% Simple example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% f(x) = [1 x sin(x)]; 30 | %% g(x) = [x x pi]; 31 | %% @end group 32 | %% 33 | %% @group 34 | %% h = f .\ g 35 | %% @result{} h(x) = (symfun) 36 | %% ⎡ π ⎤ 37 | %% ⎢x 1 ──────⎥ 38 | %% ⎣ sin(x)⎦ 39 | %% @end group 40 | %% @end example 41 | %% 42 | %% @seealso{@@symfun/rdivide} 43 | %% @end defop 44 | 45 | function h = ldivide(f, g) 46 | [vars, s1, s2] = helper_symfun_binops(f, g); 47 | h = symfun(s1 .\ s2, vars); 48 | end 49 | 50 | 51 | %!test 52 | %! syms x 53 | %! f(x) = x^2; 54 | %! assert( isa(f .\ f, 'symfun')) 55 | %! assert( isa(f .\ x, 'symfun')) 56 | -------------------------------------------------------------------------------- /inst/@symfun/mldivide.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun mldivide {(@var{f}, @var{g})} 22 | %% @defopx Operator @@symfun {@var{f} \ @var{g}} {} 23 | %% Backslash division of symbolic functions. 24 | %% 25 | %% Simple example: 26 | %% @example 27 | %% @group 28 | %% syms f(x) 29 | %% g(x) = sin(x); 30 | %% @end group 31 | %% 32 | %% @group 33 | %% h = f \ g 34 | %% @result{} h(x) = (symfun) 35 | %% sin(x) 36 | %% ────── 37 | %% f(x) 38 | %% @end group 39 | %% @end example 40 | %% 41 | %% @seealso{@@sym/mldivide} 42 | %% @end defop 43 | 44 | function h = mldivide(f, g) 45 | [vars, s1, s2] = helper_symfun_binops(f, g); 46 | h = symfun(s1 \ s2, vars); 47 | end 48 | 49 | 50 | %!test 51 | %! syms x 52 | %! f(x) = x^2; 53 | %! assert( isa(f\f, 'symfun')) 54 | %! assert( isa(f\x, 'symfun')) 55 | -------------------------------------------------------------------------------- /inst/@symfun/mrdivide.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun mrdivide {(@var{f}, @var{g})} 22 | %% @defopx Operator @@symfun {@var{f} / @var{g}} {} 23 | %% Forward slash division of symbolic functions. 24 | %% 25 | %% Simple example: 26 | %% @example 27 | %% @group 28 | %% syms f(x) 29 | %% g(x) = sin(x); 30 | %% @end group 31 | %% 32 | %% @group 33 | %% h = f / g 34 | %% @result{} h(x) = (symfun) 35 | %% f(x) 36 | %% ────── 37 | %% sin(x) 38 | %% @end group 39 | %% @end example 40 | %% 41 | %% @seealso{@@sym/mrdivide} 42 | %% @end defop 43 | 44 | function h = mrdivide(f, g) 45 | [vars, s1, s2] = helper_symfun_binops(f, g); 46 | h = symfun(s1 / s2, vars); 47 | end 48 | 49 | 50 | %!test 51 | %! syms x 52 | %! f(x) = x^2; 53 | %! assert( isa(f/f, 'symfun')) 54 | %! assert( isa(f/x, 'symfun')) 55 | -------------------------------------------------------------------------------- /inst/@symfun/mtimes.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun mtimes {(@var{f}, @var{g})} 22 | %% @defopx Operator @@symfun {@var{f} * @var{g}} {} 23 | %% Multiply symbolic functions. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% f(x) = 2*x; 30 | %% g(x) = sin(x); 31 | %% @end group 32 | %% 33 | %% @group 34 | %% h = f*g 35 | %% @result{} h(x) = (symfun) 2⋅x⋅sin(x) 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% Matrix example: 40 | %% @example 41 | %% @group 42 | %% syms x y 43 | %% f(x, y) = sym([1 2; 3 4]); 44 | %% g(x, y) = [x 0; 0 y]; 45 | %% @end group 46 | %% 47 | %% @group 48 | %% h = f*g 49 | %% @result{} h(x, y) = (symfun) 50 | %% ⎡ x 2⋅y⎤ 51 | %% ⎢ ⎥ 52 | %% ⎣3⋅x 4⋅y⎦ 53 | %% @end group 54 | %% @end example 55 | %% 56 | %% @seealso{@@symfun/times} 57 | %% @end defop 58 | 59 | function h = mtimes(f, g) 60 | [vars, s1, s2] = helper_symfun_binops(f, g); 61 | h = symfun(s1 * s2, vars); 62 | end 63 | 64 | 65 | %!test 66 | %! syms x 67 | %! f(x) = x^2; 68 | %! assert( isa(f * f, 'symfun')) 69 | %! assert( isa(f * x, 'symfun')) 70 | -------------------------------------------------------------------------------- /inst/@symfun/numel.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defmethod @@symfun numel (@var{f}) 22 | %% Number of elements in a symfun. 23 | %% 24 | %% This behaves differently than for @@sym: 25 | %% @example 26 | %% @group 27 | %% syms x y 28 | %% f(x, y) = [1 x; y 2]; 29 | %% 30 | %% numel(f) 31 | %% @result{} 1 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@sym/numel} 36 | %% @end defmethod 37 | 38 | function n = numel(f) 39 | 40 | % see issue #107, #109 41 | n = 1; 42 | 43 | end 44 | 45 | 46 | %!test 47 | %! syms x 48 | %! f(x) = x^2; 49 | %! assert(numel(f)==1) 50 | 51 | %!test 52 | %! syms x 53 | %! f(x) = [1 x]; 54 | %! assert(numel(f)==1) 55 | -------------------------------------------------------------------------------- /inst/@symfun/plus.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun plus {(@var{f}, @var{g})} 22 | %% @defopx Operator @@symfun {@var{f} + @var{g}} {} 23 | %% Add two symbolic functions together. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% f(x) = 2*x; 30 | %% g(x) = sin(x); 31 | %% @end group 32 | %% 33 | %% @group 34 | %% h = f + g 35 | %% @result{} h(x) = (symfun) 2⋅x + sin(x) 36 | %% @end group 37 | %% @end example 38 | %% 39 | %% Matrix example: 40 | %% @example 41 | %% @group 42 | %% syms x y 43 | %% f(x, y) = sym([1 2; 3 4]); 44 | %% g(x, y) = [x 0; 0 y]; 45 | %% @end group 46 | %% 47 | %% @group 48 | %% h = f + g 49 | %% @result{} h(x, y) = (symfun) 50 | %% ⎡x + 1 2 ⎤ 51 | %% ⎢ ⎥ 52 | %% ⎣ 3 y + 4⎦ 53 | %% @end group 54 | %% @end example 55 | %% 56 | %% @seealso{@@symfun/minus} 57 | %% @end defop 58 | 59 | function h = plus(f, g) 60 | [vars, s1, s2] = helper_symfun_binops(f, g); 61 | h = symfun(s1 + s2, vars); 62 | end 63 | 64 | 65 | %!test 66 | %! syms x 67 | %! f(x) = x^2; 68 | %! assert( isa(f + f, 'symfun')) 69 | %! assert( isa(f + x, 'symfun')) 70 | -------------------------------------------------------------------------------- /inst/@symfun/power.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun power {(@var{f}, @var{g})} 22 | %% @defopx Operator @@symfun {@var{f} .^ @var{g}} {} 23 | %% Symbolic function component-wise exponentiation. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x y 29 | %% f(x, y) = [x 0; 2 y]; 30 | %% g(x, y) = sym([1 2; 3 4]); 31 | %% @end group 32 | %% 33 | %% @group 34 | %% h = f .^ g 35 | %% @result{} h(x, y) = (symfun) 36 | %% ⎡x 0 ⎤ 37 | %% ⎢ ⎥ 38 | %% ⎢ 4⎥ 39 | %% ⎣8 y ⎦ 40 | %% @end group 41 | %% @end example 42 | %% 43 | %% @seealso{@@symfun/mpower} 44 | %% @end defop 45 | 46 | function h = power(f, g) 47 | [vars, s1, s2] = helper_symfun_binops(f, g); 48 | h = symfun(s1 .^ s2, vars); 49 | end 50 | 51 | 52 | %!test 53 | %! syms x 54 | %! f(x) = 2*x; 55 | %! h = f.^f; 56 | %! assert( isa(h, 'symfun')) 57 | %! assert (isequal (formula (h), (2*x)^(2*x))) 58 | 59 | %!test 60 | %! syms x 61 | %! f(x) = [x 2*x]; 62 | %! h = f.^[x 3]; 63 | %! assert( isa(h, 'symfun')) 64 | %! assert (isequal (formula (h), [x^x 8*x^3])) 65 | -------------------------------------------------------------------------------- /inst/@symfun/private/helper_symfun_binops.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function [vars,s1,s2] = helper_symfun_binops(f, g) 20 | 21 | if (isa(f,'symfun')) && (isa(g, 'symfun')) 22 | %disp('debug: symfun symfun') 23 | if ~isequal(f.vars, g.vars) 24 | error('arithmetric operators on symfuns must have same vars') 25 | end 26 | vars = f.vars; 27 | s1 = formula (f); 28 | s2 = formula (g); 29 | elseif (isa(f,'symfun')) 30 | %disp('debug: symfun sym') 31 | vars = f.vars; 32 | s1 = formula (f); 33 | s2 = g; 34 | elseif (isa(g, 'symfun')) 35 | %disp('debug: sym symfun') 36 | vars = g.vars; 37 | s1 = f; 38 | s2 = formula (g); 39 | else 40 | error('Tertium Non Datur') 41 | end 42 | 43 | -------------------------------------------------------------------------------- /inst/@symfun/private_disp_name.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @defmethod @@symfun private_disp_name (@var{f}, @var{name}) 21 | %% A string appropriate for representing the name of this symfun. 22 | %% 23 | %% Private method: this is not the method you are looking for. 24 | %% 25 | %% @end defmethod 26 | 27 | function s = private_disp_name(f, input_name) 28 | 29 | if (isempty(input_name)) 30 | s = input_name; 31 | return 32 | end 33 | 34 | vars = f.vars; 35 | if length(vars) == 0 36 | varstr = ''; 37 | else 38 | v = vars{1}; 39 | varstr = v.flat; 40 | end 41 | for i = 2:length(vars); 42 | v = vars{i}; 43 | varstr = [varstr ', ' v.flat]; 44 | end 45 | s = [input_name, '(', varstr, ')']; 46 | 47 | end 48 | 49 | 50 | %!test 51 | %! syms f(x) 52 | %! s = private_disp_name(f, 'f'); 53 | %! assert (strcmp (s, 'f(x)')) 54 | 55 | %!test 56 | %! syms x y 57 | %! g(y, x) = x + y; 58 | %! s = private_disp_name(g, 'g'); 59 | %! assert (strcmp (s, 'g(y, x)')) 60 | 61 | %!test 62 | %! syms f(x) 63 | %! assert (isempty (private_disp_name(f, ''))) 64 | -------------------------------------------------------------------------------- /inst/@symfun/rdivide.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun rdivide {(@var{f}, @var{g})} 22 | %% @defopx Operator @@symfun {@var{f} ./ @var{g}} {} 23 | %% Forward slash component division of symbolic functions. 24 | %% 25 | %% Simple example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% f(x) = [1 x sin(x)]; 30 | %% g(x) = [x x pi]; 31 | %% @end group 32 | %% 33 | %% @group 34 | %% h = f ./ g 35 | %% @result{} h(x) = (symfun) 36 | %% ⎡1 sin(x)⎤ 37 | %% ⎢─ 1 ──────⎥ 38 | %% ⎣x π ⎦ 39 | %% @end group 40 | %% @end example 41 | %% 42 | %% @seealso{@@symfun/ldivide} 43 | %% @end defop 44 | 45 | function h = rdivide(f, g) 46 | [vars, s1, s2] = helper_symfun_binops(f, g); 47 | h = symfun(s1 ./ s2, vars); 48 | end 49 | 50 | 51 | %!test 52 | %! syms x 53 | %! f(x) = x^2; 54 | %! assert( isa(f./f, 'symfun')) 55 | %! assert( isa(f./[x x^2], 'symfun')) 56 | 57 | %!test 58 | %! syms x 59 | %! f(x) = [x 2*x]; 60 | %! h = f./[x 2]; 61 | %! assert( isa(h, 'symfun')) 62 | %! assert (isequal (formula (h), [1 x])) 63 | -------------------------------------------------------------------------------- /inst/@symfun/times.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun times {(@var{f}, @var{g})} 22 | %% @defopx Operator @@symfun {@var{f} .* @var{g}} {} 23 | %% Symbolic function component-wise multiplication. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x y 29 | %% f(x, y) = sym([1 2; 3 4]); 30 | %% g(x, y) = [x 0; 2 y]; 31 | %% @end group 32 | %% 33 | %% @group 34 | %% h = f .* g 35 | %% @result{} h(x, y) = (symfun) 36 | %% ⎡x 0 ⎤ 37 | %% ⎢ ⎥ 38 | %% ⎣6 4⋅y⎦ 39 | %% @end group 40 | %% @end example 41 | %% 42 | %% @seealso{@@symfun/mtimes} 43 | %% @end defop 44 | 45 | function h = times(f, g) 46 | [vars, s1, s2] = helper_symfun_binops(f, g); 47 | h = symfun(s1 .* s2, vars); 48 | end 49 | 50 | 51 | %!test 52 | %! syms x 53 | %! f(x) = x^2; 54 | %! assert( isa(f .* f, 'symfun')) 55 | %! assert( isa(f .* x, 'symfun')) 56 | 57 | %!test 58 | %! syms x 59 | %! f(x) = [x 2*x]; 60 | %! h = f.*[x 3]; 61 | %! assert( isa(h, 'symfun')) 62 | %! assert (isequal (formula (h), [x^2 6*x])) 63 | -------------------------------------------------------------------------------- /inst/@symfun/uminus.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defop Method @@symfun uminus {(@var{f})} 22 | %% @defopx Operator @@symfun {-@var{f}} {} 23 | %% Return the negation of a symbolic function. 24 | %% 25 | %% Example: 26 | %% @example 27 | %% @group 28 | %% syms x 29 | %% f(x) = 2*x; 30 | %% h = -f 31 | %% @result{} h(x) = (symfun) -2⋅x 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{@@symfun/minus} 36 | %% @end defop 37 | 38 | function h = uminus(f) 39 | 40 | h = symfun(-formula(f), f.vars); 41 | 42 | end 43 | 44 | 45 | %!test 46 | %! % Issue #447 47 | %! syms x 48 | %! f(x) = x^2; 49 | %! assert (isa (-f, 'symfun')) 50 | 51 | %!test 52 | %! syms f(x) 53 | %! h = -f; 54 | %! assert (isa (h, 'symfun')) 55 | -------------------------------------------------------------------------------- /inst/catalan.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015 Carnë Draug 2 | %% Copyright (C) 2016, 2018-2019, 2022 Colin B. Macdonald 3 | %% Copyright (C) 2022 Chris Gorman 4 | %% 5 | %% This file is part of OctSymPy. 6 | %% 7 | %% OctSymPy is free software; you can redistribute it and/or modify 8 | %% it under the terms of the GNU General Public License as published 9 | %% by the Free Software Foundation; either version 3 of the License, 10 | %% or (at your option) any later version. 11 | %% 12 | %% This software is distributed in the hope that it will be useful, 13 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 14 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 15 | %% the GNU General Public License for more details. 16 | %% 17 | %% You should have received a copy of the GNU General Public 18 | %% License along with this software; see the file COPYING. 19 | %% If not, see . 20 | 21 | %% -*- texinfo -*- 22 | %% @documentencoding UTF-8 23 | %% @deffn Constant catalan () 24 | %% Return Catalan constant. 25 | %% 26 | %% @example 27 | %% @group 28 | %% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) >= Version("1.10")')) 29 | %% catalan () 30 | %% @result{} (sym) G 31 | %% 32 | %% vpa (catalan ()) 33 | %% @result{} (sym) 0.91596559417721901505460351493238 34 | %% @end group 35 | %% @end example 36 | %% 37 | %% @seealso{eulergamma} 38 | %% @end deffn 39 | 40 | %% Author: Carnë Draug 41 | %% Keywords: symbolic, constants 42 | 43 | function g = catalan () 44 | 45 | if (nargin ~= 0) 46 | print_usage (); 47 | end 48 | 49 | g = pycall_sympy__ ('return sympy.S.Catalan,'); 50 | end 51 | 52 | 53 | %!error catalan (sym(1)) 54 | %!assert (double (catalan ()) > 0.915965594177) 55 | %!assert (double (catalan ()) < 0.915965594178) 56 | -------------------------------------------------------------------------------- /inst/eulergamma.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015 Carnë Draug 2 | %% Copyright (C) 2016, 2018-2019, 2022 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @documentencoding UTF-8 22 | %% @deffn Constant eulergamma () 23 | %% Return Euler--Mascheroni constant. 24 | %% 25 | %% @example 26 | %% @group 27 | %% eulergamma 28 | %% @result{} (sym) γ 29 | %% 30 | %% vpa (eulergamma ()) 31 | %% @result{} (sym) 0.57721566490153286060651209008240 32 | %% @end group 33 | %% @end example 34 | %% 35 | %% @seealso{catalan} 36 | %% @end deffn 37 | 38 | %% Author: Carnë Draug 39 | %% Keywords: symbolic, constants 40 | 41 | function g = eulergamma () 42 | 43 | if (nargin ~= 0) 44 | print_usage (); 45 | end 46 | 47 | g = pycall_sympy__ ('return sympy.S.EulerGamma,'); 48 | end 49 | 50 | 51 | %!error catalan (sym(1)) 52 | %!assert (double (eulergamma ()) > 0.577215664901) 53 | %!assert (double (eulergamma ()) < 0.577215664902) 54 | -------------------------------------------------------------------------------- /inst/private/cygpath.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2022 Alex Vong 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @defun cygpath () 21 | %% Convert Windows native path to Cygwin POSIX-style path. 22 | %% 23 | %% @seealso{python_env_is_cygwin_like} 24 | %% @end defun 25 | 26 | function posix_path = cygpath (native_path) 27 | %% FIXME: only allow safe characters inside "..." 28 | if ~isempty (strfind (native_path, '"')) 29 | error ('cygpath: native path %s must not contain "', native_path); 30 | end 31 | 32 | [status, out] = system (['cygpath -u "' native_path '"']); 33 | if status ~= 0 34 | error ('cygpath: cygpath exited with status %d', status); 35 | end 36 | 37 | posix_path = regexprep (out, '[\r]?[\n]$', ''); % strip trailing newline 38 | assert (logical (regexp (posix_path, '^[^\r\n]+$'))); % validate path 39 | end 40 | -------------------------------------------------------------------------------- /inst/private/defaultpython.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2018-2019 Mike Miller 2 | %% Copyright (C) 2018, 2020-2021 Colin B. Macdonald 3 | %% 4 | %% This file is part of OctSymPy. 5 | %% 6 | %% OctSymPy is free software; you can redistribute it and/or modify 7 | %% it under the terms of the GNU General Public License as published 8 | %% by the Free Software Foundation; either version 3 of the License, 9 | %% or (at your option) any later version. 10 | %% 11 | %% This software is distributed in the hope that it will be useful, 12 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 13 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 | %% the GNU General Public License for more details. 15 | %% 16 | %% You should have received a copy of the GNU General Public 17 | %% License along with this software; see the file COPYING. 18 | %% If not, see . 19 | 20 | %% -*- texinfo -*- 21 | %% @defun defaultpython () 22 | %% A string to execute to call a Python interpreter. 23 | %% 24 | %% Distributors/vendors may find this a convenient place to change 25 | %% the default python executable, e.g., to specify "python3.8" or to 26 | %% hardcode a path to a particular executable. 27 | %% 28 | %% End-users can always override this by setting the environment 29 | %% variable @code{PYTHON} as documented in @pxref{sympref}. 30 | %% 31 | %% @end defun 32 | 33 | function python = defaultpython () 34 | 35 | % PEP394 says Python 3 installs should all provide this command 36 | python = 'python3'; 37 | 38 | if (ispc () && (~isunix ())) 39 | % 2020-03: Python.org installer/Anaconda do not provide python3 40 | python = 'python'; 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /inst/private/indent_lines.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function B = indent_lines(A, n) 20 | % indent each line in the cell array A by n spaces 21 | 22 | pad = repmat(' ', 1, n); 23 | if (0 == 1) 24 | % 27s 25 | B = cellfun(@(x) [pad x], A, 'UniformOutput', false); 26 | else 27 | % 23s 28 | B = cell(size(A)); 29 | for i = 1:numel(A) 30 | B{i} = [pad A{i}]; 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /inst/private/octave_array_to_python.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Lagu 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function r = octave_array_to_python(a) 20 | t = ''; 21 | 22 | [numrows, numcols] = size (a); 23 | 24 | if (numrows == 0) 25 | r = mat2str([]); 26 | return; 27 | 28 | elseif (numrows > 1) 29 | t = strcat('[', t); 30 | t = strcat(t, octave_array_to_python(a(1, :))); 31 | 32 | for i = 2:numrows 33 | t = strcat(t, ', '); 34 | t = strcat(t, octave_array_to_python(a(i, :))); 35 | end 36 | 37 | t = strcat(t, ']'); 38 | 39 | else 40 | t = strcat('[', t); 41 | t = strcat(t, mat2str(a(1, 1))); 42 | 43 | for i = 2:numcols 44 | t = strcat(t, ', '); 45 | t = strcat(t, mat2str(a(1, i))); 46 | end 47 | 48 | t = strcat(t, ']'); 49 | 50 | end 51 | 52 | r = t; 53 | -------------------------------------------------------------------------------- /inst/private/python_copy_vars_from.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function s = python_copy_vars_from(out, tryexcept) 20 | %private function 21 | 22 | if (nargin == 1) 23 | tryexcept = true; 24 | end 25 | 26 | if (~tryexcept) 27 | %% no error checking 28 | s = { sprintf('octoutput_drv(%s)', out) }; 29 | else 30 | %% with try-except block 31 | s = { 'try:' ... 32 | sprintf(' octoutput_drv(%s)', out) ... 33 | 'except:' ... 34 | ' echo_exception_stdout("while copying variables from Python")' ... 35 | ' raise' 36 | }; 37 | end 38 | -------------------------------------------------------------------------------- /inst/private/python_env_is_cygwin_like.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2022 Alex Vong 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @defun python_env_is_cygwin_like (pyexec) 21 | %% Check if Python @var{pyexec} is running in a Cygwin-like POSIX environment, 22 | %% such as Cygwin or MSYS2. The result is memoized to speed up subsequent 23 | %% calls. 24 | %% 25 | %% @seealso{cygpath} 26 | %% @end defun 27 | 28 | function r = python_env_is_cygwin_like (pyexec) 29 | persistent python_env_is_cygwin_like_memo 30 | 31 | if ~isempty (python_env_is_cygwin_like_memo) 32 | r = python_env_is_cygwin_like_memo; 33 | return 34 | end 35 | 36 | if ispc () 37 | if system ('where /q cygpath') ~= 0 38 | r = false; 39 | python_env_is_cygwin_like_memo = r; 40 | return 41 | end 42 | 43 | [status, out] = system ([pyexec ' -c "import os; print(os.name)"']); 44 | if status ~= 0 45 | error ('python_env_is_cygwin_like: %s exited with status %d', ... 46 | pyexec, status); 47 | end 48 | r = ~isempty (regexp (out, 'posix', 'match')); 49 | python_env_is_cygwin_like_memo = r; 50 | else 51 | r = false; 52 | python_env_is_cygwin_like_memo = r; 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /inst/private/python_header.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014, 2015, 2022 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function s = python_header() 20 | %private 21 | 22 | persistent PyStrCache 23 | 24 | if (isempty(PyStrCache)) 25 | thisdir = fileparts (mfilename ('fullpath')); 26 | pyfile = fullfile (thisdir, 'python_header.py'); 27 | PyStrCache = fileread (pyfile); 28 | end 29 | 30 | s = PyStrCache; 31 | 32 | end 33 | -------------------------------------------------------------------------------- /inst/private/show_system_info.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2022 Alex Vong 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @defun show_system_info () 21 | %% Show information about the current system. 22 | %% 23 | %% @seealso{computer, ver} 24 | %% @end defun 25 | 26 | function show_system_info () 27 | [platform, array_maxsize, endian] = computer (); 28 | arch = computer ('arch'); 29 | 30 | disp ('System info'); 31 | disp ('-----------'); 32 | disp (''); 33 | fprintf ('Platform: %s\n', platform); 34 | fprintf ('Array Maximum Size: %d\n', array_maxsize); 35 | fprintf ('Endianness: %s\n', endian); 36 | fprintf ('Architecture: %s\n', arch); 37 | ver (); 38 | disp (''); 39 | end 40 | -------------------------------------------------------------------------------- /inst/private/store_vars_in_python.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016 Abhinav Tripathi 2 | %% Copyright (C) 2016 Colin B. Macdonald 3 | %% Copyright (C) 2022 Alex Vong 4 | %% 5 | %% This file is part of OctSymPy. 6 | %% 7 | %% OctSymPy is free software; you can redistribute it and/or modify 8 | %% it under the terms of the GNU General Public License as published 9 | %% by the Free Software Foundation; either version 3 of the License, 10 | %% or (at your option) any later version. 11 | %% 12 | %% This software is distributed in the hope that it will be useful, 13 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 14 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 15 | %% the GNU General Public License for more details. 16 | %% 17 | %% You should have received a copy of the GNU General Public 18 | %% License along with this software; see the file COPYING. 19 | %% If not, see . 20 | 21 | function var_pyobj = store_vars_in_python (L) 22 | var_pyobj = py.list (); 23 | for i = 1:numel(L) 24 | x = L{i}; 25 | if (isa(x, 'sym')) 26 | var_pyobj.append (pyeval (sympy (x))) 27 | elseif (iscell (x)) 28 | var_pyobj.append (store_vars_in_python (x)) 29 | elseif (isnumeric (x) && isequal (x, [])) % See #1151 for more details 30 | var_pyobj.append (py.list ()); 31 | else 32 | var_pyobj.append(x); 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /inst/private/undo_highbyte_escapes.m: -------------------------------------------------------------------------------- 1 | function r = undo_highbyte_escapes(s) 2 | %UNDO_HIGHBYTE_ESCAPES Convert non-ascii characters into \x escapes 3 | % Suppose we have a unicode string such as 4 | % >> s = '⌈y⌉' 5 | % s = ⌈y⌉ 6 | % >> double(s) 7 | % ans = 226 140 136 121 226 140 137 8 | % 9 | % 10 | % We can escape the highbytes as in: 11 | % >> r = undo_highbyte_escapes(s) 12 | % r = \xe2\x8c\x88y\xe2\x8c\x89 13 | % 14 | % 15 | % FIXME: do a vectorized implementation, or at least skip 16 | % continuous chunks of ascii 17 | % 18 | % FIXME: probably only works on Octave, not Matlab. 19 | % 20 | % Copyright 2016-2017 Colin B. Macdonald 21 | % 22 | % Copying and distribution of this file, with or without modification, 23 | % are permitted in any medium without royalty provided the copyright 24 | % notice and this notice are preserved. This file is offered as-is, 25 | % without any warranty. 26 | 27 | d = double(s); 28 | 29 | %I = d > 127; 30 | 31 | r = ''; 32 | for j=1:length(d) 33 | if (d(j) <= 127) 34 | r = [r s(j)]; 35 | else 36 | r = [r '\x' tolower(dec2hex(d(j)))]; 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /inst/private/valid_sym_assumptions.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015, 2019 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @defun valid_sym_assumptions () 21 | %% Return list of valid assumptions. 22 | %% 23 | %% @end defun 24 | 25 | %% Reference: http://docs.sympy.org/dev/modules/core.html 26 | 27 | %% FIXME: Maybe in the future remove this file and replace with something else. 28 | 29 | 30 | function L = valid_sym_assumptions() 31 | 32 | persistent List 33 | 34 | if (isempty(List)) 35 | 36 | cmd = {'from sympy.core.assumptions import _assume_defined' 37 | 'return list(_assume_defined),'}; 38 | List = pycall_sympy__ (cmd); 39 | 40 | end 41 | 42 | L = List; 43 | 44 | end 45 | -------------------------------------------------------------------------------- /inst/private/write_lines.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2014-2015 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | function A = write_lines(f, L, xtra) 20 | %private function 21 | 22 | newl = sprintf('\n'); 23 | 24 | if (xtra) 25 | L(end+1:end+2) = {'' ''}; 26 | end 27 | 28 | fputs(f, strjoin(L, newl)); 29 | 30 | end 31 | 32 | -------------------------------------------------------------------------------- /io.github.gnu_octave.symbolic.metainfo.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | io.github.gnu_octave.symbolic 12 | org.octave.Octave 13 | Symbolic 14 | Symbolic manipulation, variable precision arithmetic, and other computer algebra features 15 | 16 |

Adds symbolic calculation features to GNU Octave. These 17 | include common Computer Algebra System tools such as algebraic 18 | operations, calculus, equation solving, Fourier and Laplace 19 | transforms, variable precision arithmetic and other features. 20 | Compatibility with other symbolic toolboxes is intended.

21 |
22 | 23 | symbolic computing 24 | computer algebra system 25 | CAS 26 | algebraic manipulation 27 | algebraic equation 28 | calculus 29 | transform 30 | solve 31 | variable precision arithmetic 32 | vpa 33 | sym 34 | Symbolic Math Toolbox 35 | 36 | https://octave.sourceforge.io/symbolic 37 | https://github.com/gnu-octave/symbolic/issues/new 38 | FSFAP 39 | GPL-3.0-or-later 40 | 41 | The Octave Community 42 | 43 | octave-maintainers@gnu.org 44 |
45 | -------------------------------------------------------------------------------- /misc/.oct-config: -------------------------------------------------------------------------------- 1 | encoding=utf-8 2 | -------------------------------------------------------------------------------- /misc/my_print_usage.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2015 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @deftypefn {Function File} {} print_usage () 22 | %% Wrapper for print_usage on Matlab. 23 | %% 24 | %% Matlab has no print_usage function. Preparing 25 | %% the Matlab package should rename this from 26 | %% "my_print_usage.m" to "print_usage.m". 27 | %% 28 | %% @seealso{error} 29 | %% @end deftypefn 30 | 31 | function print_usage () 32 | 33 | % if we are on Octave 34 | if (exist ('OCTAVE_VERSION', 'builtin')) 35 | %evalin ('caller', 'print_usage ();' ); 36 | %return 37 | end 38 | 39 | H = dbstack; 40 | name = H(2).name; 41 | 42 | msgid = sprintf('%s:invalidCall', name); 43 | errmsg = sprintf('Invalid call to "%s": see documentation', name); 44 | 45 | %error('Invalid call to "%s": see documentation', name) 46 | ME = MException(msgid, errmsg); 47 | ME.throwAsCaller(); 48 | 49 | end 50 | -------------------------------------------------------------------------------- /misc/octassert.m: -------------------------------------------------------------------------------- 1 | %% Copyright (C) 2016-2017 Colin B. Macdonald 2 | %% 3 | %% This file is part of OctSymPy. 4 | %% 5 | %% OctSymPy is free software; you can redistribute it and/or modify 6 | %% it under the terms of the GNU General Public License as published 7 | %% by the Free Software Foundation; either version 3 of the License, 8 | %% or (at your option) any later version. 9 | %% 10 | %% This software is distributed in the hope that it will be useful, 11 | %% but WITHOUT ANY WARRANTY; without even the implied warranty 12 | %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | %% the GNU General Public License for more details. 14 | %% 15 | %% You should have received a copy of the GNU General Public 16 | %% License along with this software; see the file COPYING. 17 | %% If not, see . 18 | 19 | %% -*- texinfo -*- 20 | %% @documentencoding UTF-8 21 | %% @defun octassert (@var{a},@var{b},@var{tol}) 22 | %% Wrapper for assert on Matlab. 23 | %% 24 | %% Octave's @code{assert} has this three-input version 25 | %% for testing either abs or rel tol. This only supports 26 | %% scalar @var{tol}: Octave can have a vector there. 27 | %% @end defun 28 | 29 | function octassert (varargin) 30 | 31 | if (exist ('OCTAVE_VERSION', 'builtin')) 32 | warning('why are you calling this on Octave? No need...') 33 | end 34 | 35 | if (nargin == 1) 36 | assert(varargin{1}); 37 | return 38 | elseif (nargin == 2) 39 | tol = 0; 40 | elseif (nargin == 3) 41 | tol = varargin{3}; 42 | else 43 | error('no such assert call with 4 inputs?') 44 | end 45 | 46 | a = varargin{1}; 47 | b = varargin{2}; 48 | a = a(:); 49 | b = b(:); 50 | assert (isscalar (tol)) 51 | if (tol < 0) 52 | % rel error 53 | assert (all (abs (a - b) <= abs (tol)*abs (b))) 54 | else 55 | % abs error 56 | assert (all (abs (a - b) <= abs (tol))) 57 | end 58 | 59 | end 60 | -------------------------------------------------------------------------------- /misc/octsympy_tests_matlab.m: -------------------------------------------------------------------------------- 1 | % Copyright (C) 2014-2017 Colin B. Macdonald 2 | % 3 | % This file is part of OctSymPy. 4 | % 5 | % OctSymPy is free software; you can redistribute it and/or modify 6 | % it under the terms of the GNU General Public License as published 7 | % by the Free Software Foundation; either version 3 of the License, 8 | % or (at your option) any later version. 9 | % 10 | % This software is distributed in the hope that it will be useful, 11 | % but WITHOUT ANY WARRANTY; without even the implied warranty 12 | % of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 | % the GNU General Public License for more details. 14 | % 15 | % You should have received a copy of the GNU General Public 16 | % License along with this software; see the file COPYING. 17 | % If not, see . 18 | 19 | addpath(pwd) 20 | base = 'tests_matlab'; 21 | files = dir(base); 22 | cd(base); 23 | 24 | % usually I'd just use cputime(), but some of our IPC mechanisms are 25 | % light on CPU and heavy on IO. 26 | totaltime = clock(); 27 | totalcputime = cputime(); 28 | num_tests = 0; 29 | % do tests in random order: 30 | %rng('shuffle') 31 | %for i=randperm(length(files)) 32 | for i=1:length(files) 33 | mfile = files(i).name; 34 | % detect tests b/c directory contains other stuff (e.g., surdirs and 35 | % helper files) 36 | if ( (~files(i).isdir) && strncmp(mfile, 'test', 4) && mfile(end) ~= '~') 37 | testtime = clock(); 38 | str = mfile(1:end-2); 39 | num_tests = num_tests + 1; 40 | fprintf(['>>> Running test(s) in: ' mfile ' ']); % no newline 41 | eval(str) 42 | testtime = etime(clock(), testtime); 43 | end 44 | end 45 | 46 | totaltime = etime(clock(),totaltime); 47 | totalcputime = cputime() - totalcputime; 48 | fprintf('\n***** Ran tests from %d files, %g seconds (%gs CPU) *****\n', ... 49 | num_tests, totaltime, totalcputime); 50 | cd('..') 51 | -------------------------------------------------------------------------------- /screenshot-install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnu-octave/symbolic/56ee3f2bd10b031ab30f293d0cb6c9a99ae47b7b/screenshot-install.png -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnu-octave/symbolic/56ee3f2bd10b031ab30f293d0cb6c9a99ae47b7b/screenshot.png -------------------------------------------------------------------------------- /util/.oct-config: -------------------------------------------------------------------------------- 1 | encoding=utf-8 2 | -------------------------------------------------------------------------------- /util/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Colin B. Macdonald 2 | # 3 | # Copying and distribution of this file, with or without modification, 4 | # are permitted in any medium without royalty provided the copyright 5 | # notice and this notice are preserved. This file is offered as-is, 6 | # without any warranty. 7 | 8 | OCTAVE ?= octave 9 | PYTHON ?= python 10 | 11 | .PHONY: help codegen 12 | 13 | help: 14 | @echo "Available development tasks:" 15 | @echo " codegen regenerate the auto-generated .m functions" 16 | 17 | codegen: 18 | ${PYTHON} generate_functions.py install 19 | --------------------------------------------------------------------------------