Real part of an arithmetical expression
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
Re(z
) Re(L
)
Re(z)
returns the real part of z
.
The intended use of Re
is for constant arithmetical expressions.
Especially for numbers,
of type DOM_INT
, DOM_RAT
, DOM_FLOAT
,
or DOM_COMPLEX
,
the real part is computed directly and very efficiently.
Re
can handle symbolic expressions. Properties
of identifiers are taken into account. See assume
. An identifier without any property
is assumed to be complex. See Example 2.
If Re
cannot extract the whole real part
of a symbolic expression z
, then the returned expression
contains symbolic Re
and Im
calls.
In such cases, try using the rectform
function.
See Example 3. Note that using rectform
is
computationally expensive.
The Re
function is automatically mapped to
all entries of container objects, such as arrays, lists, matrices,
polynomials, sets, and tables.
This function is sensitive to properties of identifiers set
via assume
.
The real part of 2 e^{1 + i} is:
Re(2*exp(1 + I))
Re
cannot extract the real part of symbolic
expressions containing identifiers without a value. However, in some
cases it can still simplify the input expression, as in the following
two examples:
Re(u + v*I)
Re(z + 2*I)
By default, identifiers without a value are assumed to represent
arbitrary complex numbers. You can use assume
to change this. The following
command tells the system that z
represents only
real numbers:
assume(z, Type::Real): Re(z + 2)
unassume(z)
If Re
cannot extract the real part of a symbolic
expression, try using the function rectform
. It splits a complex expression z into
its real and imaginary part and is more powerful than Re
:
Re(exp(I*sin(z))); r := rectform(exp(I*sin(z)))
Then use Re(r)
to extract the real part of r
:
Re(r)
Symbolic expressions of type "Re"
always
have the property Type::Real
, even if
no identifier of the symbolic expression has a property:
is(Re(sin(2*x)), Type::Real)
You can extend the functions Re
and Im
to
their own special mathematical functions. See the "Algorithms"
section. To do so, embed your mathematical function into a function environmentf
and
implement the behavior of the functions Re
and Im
for
this function as the slots "Re"
and "Im"
of
the function environment.
If a subexpression of the form f(u,..)
occurs
in z
, then Re
and Im
issue
the call f::Re(u,..)
and f::Im(u,..)
,
respectively, to the slot routine to determine the real and the imaginary
part of f(u,..)
, respectively.
For example, extend the function Re
for the
sine function. Of course, the function environment sin
already has a "Re"
slot.
Call your function environment Sin
in order not
to overwrite the existing system function sin
:
Sin := funcenv(Sin): Sin::Re := proc(u) // compute Re(Sin(u)) local r, s; begin r := Re(u); if r = u then return(Sin(u)) elif not has(r, {hold(Im), hold(Re)}) then s := Im(u); if not has(s, {hold(Im), hold(Re)}) then return(Sin(r)*cosh(s)) end_if end_if; return(FAIL) end:
Re(Sin(2)), Im(Sin(3*I)), Re(Sin(2 + 3*I))
The return value FAIL
tells the function Re
that Sin::Re
was
unable to determine the real part of the input expression. The result
is then a symbolic Re
call:
Re(2 + Sin(f(z)))
 

A container object: an array, an hfarray, a list, a matrix, a polynomial, a set, or a table. 
arithmetical expression or a container object containing such expressions
z
If a subexpression of the form f(u,...)
occurs
in z
and f
is a function environment, then Re
attempts
to call the slot "Re"
of f
to
determine the real part of f(u,...)
. In this way,
you can extend the functionality of Re
to your
own special mathematical functions.
The slot "Re"
is called with the arguments u
,...
of f
. If the slot routine f::Re
is
not able to determine the real part of f(u,...)
,
then it must return FAIL
.
If f
does not have a slot "Re"
,
or if the slot routine f::Re
returns FAIL
,
then f(u,...)
is replaced by the symbolic call Re(f(u,...))
in
the returned expression. See Example 5.
Similarly, if an element d
of a library domainT
occurs
as a subexpression of z
, then Re
attempts
to call the slot "Re"
of that domain with d
as
argument to compute the real part of d
.
If the slot routine T::Re
is unable to determine
the real part of d
, then it returns FAIL
.
If T
does not have a slot "Re"
,
or if the slot routine T::Re
returns FAIL
,
then d
is replaced by the symbolic call Re(d)
in
the returned expression.