Documentation Center

  • Trial Software
  • Product Updates

Special Functions of Applied Mathematics

Evaluate Special Functions Numerically Using mfun

Over 50 of the special functions of classical applied mathematics are available in the toolbox. These functions are accessed with the mfun function, which numerically evaluates special functions for the specified parameters. This allows you to evaluate functions that are not available in standard MATLAB® software, such as the Fresnel cosine integral. In addition, you can evaluate several MATLAB special functions in the complex plane, such as the error function erf.

For example, suppose you want to evaluate the hyperbolic cosine integral at the points 2 + i, 0, and 4.5. Look in the tables in Syntax and Definitions of mfun Special Functions to find the available functions and their syntax. You can also enter the command

mfunlist

to see the list of functions available for mfun. This list provides a brief mathematical description of each function, its mfun name, and the parameters it needs. From the tables or list, you can see that the hyperbolic cosine integral is called Chi, and it takes one complex argument.

Type

z = [2 + i 0 4.5];
w = mfun('Chi', z)

which returns

w = 
   2.0303 + 1.7227i      NaN + 0.0000i  13.9658 + 0.0000i

mfun returns the special value NaN where the function has a singularity. The hyperbolic cosine integral has a singularity at z = 0.

    Note:   mfun functions perform numerical, not symbolic, calculations. The input parameters should be scalars, vectors, or matrices of type double, or complex doubles, not symbolic variables.

Syntax and Definitions of mfun Special Functions

The following conventions are used in the next table, unless otherwise indicated in the Arguments column.

x, y

real argument

z, z1, z2

complex argument

m, n

integer argument

mfun Special Functions

Function Name

Definition

mfun Name

Arguments

Bernoulli numbers and polynomials

Generating functions:

bernoulli(n)

bernoulli(n,t)

Bessel functions

BesselI, BesselJ—Bessel functions of the first kind.
BesselK, BesselY—Bessel functions of the second kind.

BesselJ(v,x)

BesselY(v,x)

BesselI(v,x)

BesselK(v,x)

v is real.

Beta function

Beta(x,y)

 

Binomial coefficients

binomial(m,n)

 

Complete elliptic integrals

Legendre's complete elliptic integrals of the first, second, and third kind. This definition uses modulus k. The numerical ellipke function and the MuPAD® functions for computing elliptic integrals use the parameter .

EllipticK(k)

EllipticE(k)

EllipticPi(a,k)

a is real, –∞ < a < ∞.

k is real, 0 < k < 1.

Complete elliptic integrals with complementary modulus

Associated complete elliptic integrals of the first, second, and third kind using complementary modulus. This definition uses modulus k. The numerical ellipke function and the MuPAD functions for computing elliptic integrals use the parameter .

EllipticCK(k)

EllipticCE(k)

EllipticCPi(a,k)

a is real, –∞ < a < ∞.

k is real, 0 < k < 1.

Complementary error function and its iterated integrals

erfc(z)

erfc(n,z)

n ≥ -1

Dawson's integral

dawson(x)

 

Digamma function

Psi(x)

 

Dilogarithm integral

dilog(x)

x > 1

Error function

erf(z)

 

Euler numbers and polynomials

Generating function for Euler numbers:

euler(n)

euler(n,z)

n ≥ 0

Exponential integrals

Ei(n,z)

Ei(x)

n ≥ 0

Real(z) > 0

Fresnel sine and cosine integrals

FresnelC(x)

FresnelS(x)

 

Gamma function

GAMMA(z)

 

Harmonic function

harmonic(n)

n > 0

Hyperbolic sine and cosine integrals

Shi(z)

Chi(z)

 

(Generalized) hypergeometric function

where j and m are the number of terms in n and d, respectively.

hypergeom(n,d,x)

where

n = [n1,n2,...]

d = [d1,d2,...]

n1,n2,... are real.

d1,d2,... are real and nonnegative.

Incomplete elliptic integrals

Legendre's incomplete elliptic integrals of the first, second, and third kind. This definition uses modulus k. The numerical ellipke function and the MuPAD functions for computing elliptic integrals use the parameter .

EllipticF(x,k)

EllipticE(x,k)

EllipticPi(x,a,k)

0 < x ≤ ∞.

a is real, –∞ < a < ∞.

k is real, 0 < k < 1.

Incomplete gamma function

GAMMA(z1,z2)

z1 = a
z2 = z

 

Logarithm of the gamma function

lnGAMMA(z)

 

Logarithmic integral

Li(x)

x > 1

Polygamma function

where is the Digamma function.

Psi(n,z)

n ≥ 0

Shifted sine integral

Ssi(z)

 

The following orthogonal polynomials are available using mfun. In all cases, n is a nonnegative integer and x is real.

Orthogonal Polynomials

Polynomial

mfun Name

Arguments

Chebyshev of the first and second kind

T(n,x)

U(n,x)

 

Gegenbauer

G(n,a,x)

a is a nonrational algebraic expression or a rational number greater than -1/2.

Hermite

H(n,x)

 

Jacobi

P(n,a,b,x)

a, b are nonrational algebraic expressions or rational numbers greater than -1.

Laguerre

L(n,x)

 

Generalized Laguerre

L(n,a,x)

a is a nonrational algebraic expression or a rational number greater than -1.

Legendre

P(n,x)

 

Diffraction Example

This example is from diffraction theory in classical electrodynamics. (J.D. Jackson, Classical Electrodynamics, John Wiley & Sons, 1962).

Suppose you have a plane wave of intensity I0 and wave number k. Assume that the plane wave is parallel to the xy-plane and travels along the z-axis as shown below. This plane wave is called the incident wave. A perfectly conducting flat diffraction screen occupies half of the xy-plane, that is x < 0. The plane wave strikes the diffraction screen, and you observe the diffracted wave from the line whose coordinates are (x, 0, z0), where z0 > 0.

The intensity of the diffracted wave is given by

where

and and are the Fresnel cosine and sine integrals:

How does the intensity of the diffracted wave behave along the line of observation? Since k and z0 are constants independent of x, you set

and assume an initial intensity of I0 = 1 for simplicity.

The following code generates a plot of intensity as a function of x:

x = -50:50;
C = mfun('FresnelC',x);
S = mfun('FresnelS',x);
I0 = 1;
T = (C+1/2).^2 + (S+1/2).^2;
I = (I0/2)*T;
plot(x,I);
xlabel('x');
ylabel('I(x)');
title('Intensity of Diffracted Wave');

You see from the graph that the diffraction effect is most prominent near the edge of the diffraction screen (x = 0), as you expect.

Note that values of x that are large and positive correspond to observation points far away from the screen. Here, you would expect the screen to have no effect on the incident wave. That is, the intensity of the diffracted wave should be the same as that of the incident wave. Similarly, x values that are large and negative correspond to observation points under the screen that are far away from the screen edge. Here, you would expect the diffracted wave to have zero intensity. These results can be verified by setting

x = [Inf -Inf]

in the code to calculate I.

Was this topic helpful?