1%% Copyright (C) 2016-2017 Lagu 2%% Copyright (C) 2017, 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 <http://www.gnu.org/licenses/>. 19 20%% -*- texinfo -*- 21%% @documentencoding UTF-8 22%% @defmethod @@sym ellipticK (@var{m}) 23%% Complete elliptic integral of the first kind. 24%% 25%% The complete elliptic integral of the first kind 26%% with parameter @var{m} is defined by: 27%% @example 28%% @group 29%% syms m 30%% ellipticK (m) 31%% @result{} ans = (sym) K(m) 32%% @end group 33%% 34%% @group 35%% rewrite (ans, 'Integral') % doctest: +SKIP 36%% @result{} ans = (sym) 37%% π 38%% ─ 39%% 2 40%% ⌠ 41%% ⎮ 1 42%% ⎮ ────────────────── dα 43%% ⎮ _______________ 44%% ⎮ ╱ 2 45%% ⎮ ╲╱ 1 - m⋅sin (α) 46%% ⌡ 47%% 0 48%% @end group 49%% @end example 50%% 51%% Examples: 52%% @example 53%% @group 54%% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) > Version("1.3")')) 55%% diff (ellipticK (m), m) 56%% @result{} (sym) 57%% -(1 - m)⋅K(m) + E(m) 58%% ──────────────────── 59%% 2⋅m⋅(1 - m) 60%% @end group 61%% 62%% @group 63%% vpa (ellipticK (sym (pi)/4)) 64%% @result{} (sym) 2.2252536839853959577044373301346 65%% @end group 66%% @end example 67%% 68%% There are other conventions for the inputs of elliptic integrals, 69%% @pxref{@@sym/ellipticF}. 70%% 71%% @seealso{@@sym/ellipke, @@sym/ellipticF, @@sym/ellipticE, @@sym/ellipticPi} 72%% @end defmethod 73 74 75function y = ellipticK (m) 76 if (nargin > 1) 77 print_usage (); 78 end 79 80 % y = ellipticF (sym (pi)/2, m); 81 y = elementwise_op ('elliptic_k', m); 82 83end 84 85 86%!error <Invalid> ellipticK (sym(1), 2) 87 88%!assert (isequal (ellipticK (sym (0)), sym (pi)/2)) 89%!assert (isequal (ellipticK (sym (-inf)), sym (0))) 90 91%!assert (double (ellipticK (sym (1)/2)), 1.854074677, 10e-10) 92%!assert (double (ellipticK (sym (pi)/4)), 2.225253684, 10e-10) 93%!assert (double (ellipticK (sym (-55)/10)), 0.9324665884, 10e-11) 94 95%!test 96%! % compare to double ellipke 97%! m = 1/5; 98%! ms = sym(1)/5; 99%! [K, E] = ellipke (m); 100%! assert (double (ellipticK (ms)), K, -1e-15) 101%! assert (double (ellipticE (ms)), E, -1e-15) 102 103%!test 104%! % compare to double ellipke 105%! if (exist ('OCTAVE_VERSION', 'builtin')) 106%! m = -10.3; 107%! ms = -sym(103)/10; 108%! [K, E] = ellipke (m); 109%! assert (double (ellipticK (ms)), K, -1e-15) 110%! assert (double (ellipticE (ms)), E, -1e-15) 111%! end 112 113%!test 114%! % compare to Maple 115%! us = vpa (ellipticK (sym (7)), 40); 116%! % > evalf(EllipticK(sqrt(7)), 40); 117%! maple = vpa ('0.6168027921799632674669917683443602673441', 40) - ... 118%! vpa ('0.9114898734184488922164103102629560336918j', 40); 119%! assert (abs (double (maple - us)), 0, 1e-39) 120