46 #define DO_BESSEL(type, alpha, x, scaled, ierr, result) \
52 result = besselj (alpha, x, scaled, ierr); \
56 result = bessely (alpha, x, scaled, ierr); \
60 result = besseli (alpha, x, scaled, ierr); \
64 result = besselk (alpha, x, scaled, ierr); \
68 result = besselh1 (alpha, x, scaled, ierr); \
72 result = besselh2 (alpha, x, scaled, ierr); \
84 error (
"%s: expecting scalar or matrix as %s argument", fn, arg);
93 int nargin = args.
length ();
95 if (nargin == 2 || nargin == 3)
101 bool rpt_error =
false;
108 if (opt_val != 0.0 && opt_val != 1.0)
110 scaled = (opt_val == 1.0);
117 error (
"%s: OPT must be 0 (or false) or 1 (or true)", fn);
129 float alpha = args(0).float_value ();
142 DO_BESSEL (type, alpha, x, scaled, ierr, result);
145 retval(1) =
static_cast<float> (
ierr);
162 DO_BESSEL (type, alpha, x, scaled, ierr, result);
181 bool args0_is_row_vector = (dv0 (1) == dv0.
numel ());
182 bool args1_is_col_vector = (dv1 (0) == dv1.
numel ());
184 if (args0_is_row_vector && args1_is_col_vector)
198 DO_BESSEL (type, ralpha, cx, scaled, ierr, result);
226 DO_BESSEL (type, alpha, x, scaled, ierr, result);
246 DO_BESSEL (type, alpha, x, scaled, ierr, result);
266 double alpha = args(0).double_value ();
279 DO_BESSEL (type, alpha, x, scaled, ierr, result);
282 retval(1) =
static_cast<double> (
ierr);
298 DO_BESSEL (type, alpha, x, scaled, ierr, result);
317 bool args0_is_row_vector = (dv0 (1) == dv0.
numel ());
318 bool args1_is_col_vector = (dv1 (0) == dv1.
numel ());
320 if (args0_is_row_vector && args1_is_col_vector)
322 RowVector ralpha = args(0).row_vector_value ();
334 DO_BESSEL (type, ralpha, cx, scaled, ierr, result);
362 DO_BESSEL (type, alpha, x, scaled, ierr, result);
381 DO_BESSEL (type, alpha, x, scaled, ierr, result);
406 @deftypefn {Built-in Function} {[@var{j}, @var{ierr}] =} besselj (@var{alpha}, @var{x}, @var{opt})\n\
407 @deftypefnx {Built-in Function} {[@var{y}, @var{ierr}] =} bessely (@var{alpha}, @var{x}, @var{opt})\n\
408 @deftypefnx {Built-in Function} {[@var{i}, @var{ierr}] =} besseli (@var{alpha}, @var{x}, @var{opt})\n\
409 @deftypefnx {Built-in Function} {[@var{k}, @var{ierr}] =} besselk (@var{alpha}, @var{x}, @var{opt})\n\
410 @deftypefnx {Built-in Function} {[@var{h}, @var{ierr}] =} besselh (@var{alpha}, @var{k}, @var{x}, @var{opt})\n\
411 Compute Bessel or Hankel functions of various kinds:\n\
415 Bessel functions of the first kind. If the argument @var{opt} is 1 or true,\n\
416 the result is multiplied by @w{@code{exp (-abs (imag (@var{x})))}}.\n\
419 Bessel functions of the second kind. If the argument @var{opt} is 1 or true,\n\
420 the result is multiplied by @code{exp (-abs (imag (@var{x})))}.\n\
424 Modified Bessel functions of the first kind. If the argument @var{opt} is 1\n\
425 or true, the result is multiplied by @code{exp (-abs (real (@var{x})))}.\n\
429 Modified Bessel functions of the second kind. If the argument @var{opt} is 1\n\
430 or true, the result is multiplied by @code{exp (@var{x})}.\n\
433 Compute Hankel functions of the first (@var{k} = 1) or second (@var{k}\n\
434 = 2) kind. If the argument @var{opt} is 1 or true, the result is multiplied\n\
435 by @code{exp (-I*@var{x})} for @var{k} = 1 or @code{exp (I*@var{x})} for\n\
439 If @var{alpha} is a scalar, the result is the same size as @var{x}.\n\
440 If @var{x} is a scalar, the result is the same size as @var{alpha}.\n\
441 If @var{alpha} is a row vector and @var{x} is a column vector, the\n\
442 result is a matrix with @code{length (@var{x})} rows and\n\
443 @code{length (@var{alpha})} columns. Otherwise, @var{alpha} and\n\
444 @var{x} must conform and the result will be the same size.\n\
446 The value of @var{alpha} must be real. The value of @var{x} may be\n\
449 If requested, @var{ierr} contains the following status information\n\
450 and is the same size as the result.\n\
457 Input error, return @code{NaN}.\n\
460 Overflow, return @code{Inf}.\n\
463 Loss of significance by argument reduction results in less than\n\
464 half of machine accuracy.\n\
467 Complete loss of significance by argument reduction, return @code{NaN}.\n\
470 Error---no computation, algorithm termination condition not met,\n\
471 return @code{NaN}.\n\
480 @deftypefn {Built-in Function} {[@var{y}, @var{ierr}] =} bessely (@var{alpha}, @var{x}, @var{opt})\n\
489 @deftypefn {Built-in Function} {[@var{i}, @var{ierr}] =} besseli (@var{alpha}, @var{x}, @var{opt})\n\
498 @deftypefn {Built-in Function} {[@var{k}, @var{ierr}] =} besselk (@var{alpha}, @var{x}, @var{opt})\n\
505 DEFUN (besselh, args, nargout,
507 @deftypefn {Built-in Function} {[@var{h}, @var{ierr}] =} besselh (@var{alpha}, @var{k}, @var{x}, @var{opt})\n\
513 int nargin = args.
length ();
519 else if (nargin == 3 || nargin == 4)
528 tmp_args(2) = args(3);
530 tmp_args(1) = args(2);
531 tmp_args(0) = args(0);
538 error (
"besselh: expecting K = 1 or 2");
541 error (
"besselh: invalid value of K");
551 @deftypefn {Built-in Function} {[@var{a}, @var{ierr}] =} airy (@var{k}, @var{z}, @var{opt})\n\
552 Compute Airy functions of the first and second kind, and their derivatives.\n\
556 K Function Scale factor (if \"opt\" is supplied)\n\
557 --- -------- ---------------------------------------\n\
558 0 Ai (Z) exp ((2/3) * Z * sqrt (Z))\n\
559 1 dAi(Z)/dZ exp ((2/3) * Z * sqrt (Z))\n\
560 2 Bi (Z) exp (-abs (real ((2/3) * Z * sqrt (Z))))\n\
561 3 dBi(Z)/dZ exp (-abs (real ((2/3) * Z * sqrt (Z))))\n\
565 The function call @code{airy (@var{z})} is equivalent to\n\
566 @code{airy (0, @var{z})}.\n\
568 The result is the same size as @var{z}.\n\
570 If requested, @var{ierr} contains the following status information and\n\
571 is the same size as the result.\n\
578 Input error, return @code{NaN}.\n\
581 Overflow, return @code{Inf}.\n\
584 Loss of significance by argument reduction results in less than half\n\
585 of machine accuracy.\n\
588 Complete loss of significance by argument reduction, return @code{NaN}.\n\
591 Error---no computation, algorithm termination condition not met,\n\
592 return @code{NaN}.\n\
598 int nargin = args.
length ();
600 if (nargin > 0 && nargin < 4)
602 bool scale = (nargin == 3);
608 kind = args(0).int_value ();
612 if (kind < 0 || kind > 3)
613 error (
"airy: expecting K = 0, 1, 2, or 3");
616 error (
"airy: K must be an integer value");
621 int idx = nargin == 1 ? 0 : 1;
623 if (args(idx).is_single_type ())
633 result =
biry (z, kind == 3, scale, ierr);
635 result =
airy (z, kind == 1, scale, ierr);
643 error (
"airy: Z must be a complex matrix");
655 result =
biry (z, kind == 3, scale, ierr);
657 result =
airy (z, kind == 1, scale, ierr);
665 error (
"airy: Z must be a complex matrix");
ComplexNDArray complex_array_value(bool frc_str_conv=false) const
Complex besselk(double alpha, const Complex &x, bool scaled, octave_idx_type &ierr)
Complex besseli(double alpha, const Complex &x, bool scaled, octave_idx_type &ierr)
OCTINTERP_API void print_usage(void)
octave_idx_type length(void) const
#define DO_BESSEL(type, alpha, x, scaled, ierr, result)
bool is_scalar_type(void) const
bool is_numeric_type(void) const
Complex airy(const Complex &z, bool deriv, bool scaled, octave_idx_type &ierr)
F77_RET_T const double const double double const octave_idx_type octave_idx_type * ierr
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
static void gripe_bessel_arg(const char *fn, const char *arg)
bool is_bool_type(void) const
FloatComplex float_complex_value(bool frc_str_conv=false) const
octave_value_list do_bessel(enum bessel_type type, const char *fn, const octave_value_list &args, int nargout)
FloatComplexNDArray float_complex_array_value(bool frc_str_conv=false) const
Complex biry(const Complex &z, bool deriv, bool scaled, octave_idx_type &ierr)
Complex besselj(double alpha, const Complex &x, bool scaled, octave_idx_type &ierr)
bool bool_value(bool warn=false) const
Array< octave_value > array_value(void) const
Complex bessely(double alpha, const Complex &x, bool scaled, octave_idx_type &ierr)
Complex complex_value(bool frc_str_conv=false) const
FloatComplexColumnVector float_complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
void scale(Matrix &m, double x, double y, double z)
std::complex< float > FloatComplex
ComplexColumnVector complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
std::complex< double > Complex
bool is_single_type(void) const
double double_value(bool frc_str_conv=false) const
F77_RET_T const double * x