An Introduction to MuPAD

(These are some excerpts from the online MuPAD) tutorial.

Table of contents

        Starting MuPAD
        Closing MuPAD and Saving Files
        Mathematical Constants
        Computing with Numbers
        Explanations and Help
        Exact Computations
        Numerical Approximations
        Introductory Examples
        Curve Sketching
        Identifiers and Their Values
        Substitution: subs
        Differentiation
        Integration
        Plotting Graphs
               2-dimensional plots
             3-dimenisonal plots
        Integration by Parts and Change of Variables

Starting MuPAD

Once you have logged in to either Fermat (or Gauss) using Cygwin, you can launch MuPAD by opening a terminal screen using the terminal screen launcher on the panel at the bottom.  You now have a screen with a prompt and you simply enter xmupad.

[username@fermat username]:$xmupad
The following are the screens that you should be using in linux.  The first screen is the linux desktop (called the Gnome desktop)
and the second screen is the desktop with a terminal window opened.

 
 


 
 

Below is the view of a new session of MuPAD:


 

This calls the MuPAD program and a session is launched.  MuPAD provides a very robust help system which you can consult during a session to find details about MuPAD's functions, syntax, graphics capabilities, etc.  Requesting help is probably the most frequently called command for a beginning user.  The first section will describe the help system available to you through MuPAD.  The following sections describes how to use MuPAD as a "super calculator".  Then we introduce some basic system functions for symbolic computations.  This document is written informally and gives you a first insight into the symbolic features of the system.

After starting a session, you can enter commands in the MuPAD language.  The system awaits your input when the MuPAD prompt appears on the screen which is the >> symbol.  If you press the <Enter> key this finishes your input and MuPAD evaluates the command that was entered.  Holding the <Shift> key while pressing <Enter> gives a line feed and MuPAD is still in input mode.

If you enter

>> sin(3.141)

and then press <Enter> , the result is:

                                            0.005926535551

is printed on the screen.  The system evaluates the sine function at 3.141 and returns a floating point approximation of the value, similar to your calculator.

If you terminate your command with a colon, then MuPAD executes the command without printing the result to the screen.  Then enables you to suppress output of irrelevant intermediate results.  You can enter more that one command in a row.  Two subsequent commands must be separated by a colon or a semi-colon, depending on whether the result of the first command is to be printed to the screen or not.

>>diff(cos(x^2),x);int(last(1),x)
                                        cos(x^2)

We will describe the operators diff and int in more detail later, but as you probably have already guessed they stand for the differentiation and integration.
 

Saving Your Data  and Closing MuPAD

You may save any MuPAD session or graph simply by using the File pull-down menu in the tool bar at the top of the MuPAD session window.  You can save the file in your home directory using a file name of your choice.  For more information about files and file management see the Linux help pages.   If you have created a graph, MuPAD opens a new window called Vcam.
This file can be saved with its own file name.  Saving the MuPAD session, will not save the graph, but you can recreate the graph by executing the plot command from the saved MuPAD session.

To close a MuPAD session or Vcam graphics screen, you may use the close box at the upper right hand corner of the window or use the File pull down menu from the tool bar at the top of the window.

You may log out of your Linux account by clicking on the Gnome footprint in the panel at the bottom of the desktop (see the screens in Starting MuPAD).  This brings up a pull-down menu from which you can log out of your account.

To return to windows and log out  of  your Linux account simultaneously, you may simply use the keystrokes <Alt><F4>.
Before you log out or before you return to windows, be sure that you have saved all your data as you data will be lost otherwise.

Mathematical Constants

MuPAD knows all common mathematical constants.  The following table lists the most of the constants that you will encounter:
 
 
Mathematical Symbol
MuPAD's notation
Value (floating-point approx)
e
E or exp(1)
2.718...
p
PI
3.14159...
i
I
sqrt(-1)

Computing with Numbers

In computing with numbers, MuPAD behaves like a pocket calculator.  For example, if you input a rational number:

>>2 + 3/2
                                                7/2
You can see that MuPAD returns exact results (and not rounded floating-point numbers) when dealing with integers and rational numbers.

>>(2 - (3/4*5))/(2/3 + 4/7)^2
                                                21609/10816

The symbol ^ represents exponentiation.  MuPAD can compute big numbers.  You might try entering

>>1324^124

which is a fairly big number.

In addition a variety of functions that operate on numbers such as the factorial function n! is available.

>> 8!
                                                    40320

The function isprime checks whether a positive integer is prime.  It returns either TRUE or FALSE.  Using ifactor, you can obtain the prime factorization:

>>isprime(123456789)
                                                    FALSE

>>ifactor(123456789)
                                   2
                                3    3607   3803

Suppose we want to compute the square root of 28.  This is not a rational number.  Thus

>>sqrt(28)
                                        1/2
                                            2 7
 
 

Explanations and Help


If you do not know the correct MuPAD command, then you can obtain this information from the online help system.  For example many MuPAD routines, the function info return a brief explanation:

>>info(solve)

solve -- solve equations and inequalities [try ?solve\
for options]

>>info(ln)

ln -- the natural logarithm

The help page of the corresponding function will provide more detailed information.  You can obtain it bo entering help("name"), where name is the name of the function.  The function help expects its argument to be a string, which are generated by double quotes " in MuPAD.  The operator ? is a short form for help.It can be used without parenthesis or quotes.  Thus you can use the following command:

>> ?solve

This command gives many more details about solve  than you get via info(solve).  Notice that it opens a new dialog window from which you can explore the entire help system.
 

Exact Computations


We will look at how MuPAD works with exact representation with some examples.

>>sqrt(28)
                                            1/2
                                    2   7

The result of the simplification of sqrt(28) is the exact value 2*7^(1/2).  Note that 7^(1/2) is the positive solution to the equation x^2 = 7.  MuPAD views 7^(1/2) as a genuine object with certain properties (namely that its square can be simplified to 7).  The system applies these properties when computing with these objects.  For example:

>>sqrt(7)^4

                                        49

As another example for exact computation, determine the limit of (1 + 1/n)^n as n goes to infinity.

>> limit((1 + 1/n)^n, n = infinity)

                                exp(1)

The identifier exp  represents the exponential function.  The Euler number e is represented exactly by the symbol exp(1) and MuPAD knows the rules of manipulation with this object.  For example:

>>ln(1/exp(1)

                                -1

The identifies E denotes the same object in MuPAD, namely the base of the natural logarithm (e = exp(1) = 2.71828...).
 

Numerical Approximation

Besides exact computations, MuPAD can also perform numerical approximations similar to your hand held calculator.  You can find a decimal approximation to sqrt(28) by entering the command:

>>float(sqrt(28))

                        5.291502622
The precision ot the approximation depends on the value to the global variable DIGITS, which determines the number of decimal digits for numerical computations.  Its default value is 10:

>>DIGITS; float(67473/6728)
                                                 10
                                       10.02868609

Global variables such as DIGITS affect the behavior of MuPAD and also are called environmental variables.  You can find a complete list of all environment  variables in the Section "Environment Variables" of the MuPAD Quick Reference .  The variable DIGITS can assume any integral value between 1 and 2^32 - 1;

>>DIGITS := 25: float(67473/6728) ; DIGITS := 10;
                                            10.02866860879904875148632

We have reset the value of DIGITS to 10 for the following computations.  This can also be achieved by the command delete(DIGITS).  For arithmetic operations with numbers, MuPAD automatically uses approximate computations as soon as at least one of the numbers involved is a floating-point value:

>> (1.0 + (5/2*3))/(1/7+7/9)^2
                            10.02868609
Note that none of the two following calls

>> 2/3*sin(2), 0.6666666666*sin(2)

results in an approximate computation of sin(2)., since technically sin(2) is an expression representing the exact value of sin(2), since technically sin(2) is an expression representing the exact value of sin(2) and not a number:

               2 sin(2)
            -----------, 0.6666666666 sin(2)
                   3

The separation of both values by a comma generates a special data type, namely a sequence, which is described later.  You have to use a floating-point representation of the above expressions:

>>float(2/3*sin(2)), 0.6666666666*float(sin(2))
                            0.6061982846, 0.6061982845
 
 

Introductory Examples


A symbolic expression in MuPAD may contain undetermined quantities (identifiers).  The following expression contains two unknowns x and y:

>> f := y^2 + 4*x + 6*x^2 + 4*x^3 + x^4
                                   2           3        2         4
                    4 x + 6 x    + 4 x      + y    +  x

Note the use of the assignment operator :=, we have assigned the expression to an identifer f, which can now be used as an abbreviation for the expression.  We may say that the latter is the value of the identifier f.  Note that MuPAD has interchanged the order of the terms.

MuPAD offers the system function diff for differentiation expressions:

>> diff(f, x), diff(f, y)
                                 2        3
            12 x + 12 x    + 4 x     + 4, 2 y
Here we have differentiated f with respect to both variables x andy.

You may obtain higher derivatives either by nested calls of diff, or a single call:

>>diff(diff(diff(f, x), x), x), diff(f, x, x, x)

             24 x + 24, 24 x + 24

Alternatively, you can use the differential operator ', which maps a function to its derivative;

>> sin', sin'(x)
                            cos, cos(x)

The symbol ' is a shortcut form of the differential operator D.  The call D(function) returns the derivative:

>>D(sin) , D(sin(x))

                                    cos, cos(x)

You can compute integral by unsing int.  The following command computes a definite integral on the real interval between -1, and 2:

>>int(f , x = -1 .. 2)
                            2
                        3y   +228/5
 
 

The next command determines an indefinite integral and returns an expression containing the integral of x and a symbolic parameter y:

>> int(f, x)
                      2         3       4          5             2
                2 x   + 2 x    + x     +  x  /5 + x y

If you try to compute  the definite integral of an expression and it cannot be expressed as an elementary function, the integral is returned as unevaluated:

>> integrand :=  int(1/exp(x^2) +1, x)

                             /         1          \
                     int   |------------------|   ,x
                            | exp(x^2) +1  |
                             \                     /

Nonetheless this object has mathematical properties and MuPAD recognizes that its derivative is an integrand:

>>diff(integrand,x)

                            1
                    --------------
                              2
                    exp(x   ) +1
 

    One can also compute the definite integral:
>>  int(1/exp(x^2) +1, x=0..1)

                             /         1          \
                     int   |------------------|   ,x = 0 .. 1
                            | exp(x^2) +1  |
                             \                     /
MuPAD returns this expression for the definite integral as the exact answer given is as simple as possible.  However, one can obtain a numerical approximation for the definite integral by entering:

>> float(%)
                                        .41946648
The % symbol (which is equivalent to last(1)) is an abbreviation for the last computed object.

    MuPAD knows most important mathematical functions such as square root sqrt, the exponential function exp(x), the trigonometry functions, sin, cos, tan, the hyperbolic functions sinh, cosh, tanh and their corresponding inverse functions ln, arcsin, arccos, arctan, arcsinh, arccosh, arctanh as well as many other mathematical functions.

    It can compute floating-point approximations such as float(exp(1)) = 2.818... and know special values such as sin(PI) = 0.  If you call these functions they are left unevaluated, since this is the simplest exact representation of their corresponding values:

>> sqrt(2), exp(1), sin(x + y)
                               1/2
                            2      ,exp (1),  sin(x + y)

A  feature of MuPAD is to simplify or transform such expressions using rules for computations.  For example

>> expand(exp(x + y)), expand(sin(x + y))

        exp(x) exp(y),   cos(x) sin(y) + cos( x)sin(y)

    Another feature of a computer algebra system is to manipulate and simplify expressions/  Besides expand, MuPAD provides the functions collect, combine, normal, partfrac, radsimp, rewrite and simply for manipulation.

The function normal finds a common denominator for rational expressions.

>> f:= x/(1+x) - 2/(1-x): g = normal(f)
                               2
                            x   + x  + 2
                          --------------
                                  2
                              x      - 1

The function normal cancels common factors in the numerator and denominator:

>> normal (x^2/(x + y) - y^2/(x + y))

                                    x - y
Conversely, partfrac (short for partial fraction) decomposes a rational expression into a sum of rational terms with simple denominators:

>>  partfrac(g, x)

                        2                    1
            ----------  -   -----------  + 1
                    x - 1                x + 1

The function simplify is a universal simplifier and tries to find a representation that is an simple as possible:

>> simplify (exp(x) - 1)/(exp(x/2) + 1))
                         /    x   \
                    exp|   --   |   -1
                         \    2  /

You may control the simplification by supplying simplify with additional arguments (see ?simplify).  The function radsimplify simplifies arithmetical expressions containing radicals (roots):

>> f := sqrt(4 + 2*sqrt(3)):f = radsimp(f)

                       1/2     1/2       1/2       1/2
                    2        (3    + 2)        = 3       + 1

Here we have generated an equation which is a genuine MuPAD object.  Another important function is factor, which decomposes an expression into a product of simpler ones:

>>factor (x^3 + 3x^2 + 3*x + 2),
     factor((2*x*y -2*x - 2* y + y^2),
     factor(x^2/(x + y) - z^2/(x + y))
                    3                                         (x + z)  (-x + z)
        (x + 1)    , (x + y - 2)  (x + y), - ------------------------------
                                                                    x + y

The function limit does what its name suggests.  The function sin(x)/x has a removeable discontinuity at x  = 0.  Its limit for x going to 0 is 1:

>>limit(sin(x),x ,x = 0)

                                                1
    In a MuPAD session you can define functions of your own in several ways.  A simple and intuitive method is to use the arrow operator -> (the minus symbol followed by the "greater than " symbol);

>> F := x -> (x^2):  F(x), F(y), F(a + b), F'(x)

                           2              2              2
                        x      ,      y    ,  (a + b)    ,    2x

You can obtain visualizations of mathematical object immediately.  You can obtain 2 and 3 dimensional plots of graphs of functions using plotfunc2d and plotfunc3d.

>>plotfunc2d(sin(x)/x,x = -PI..PI)
 


 
 
 
 
 
 
 
 

>>plotfunc3d(sin(x^2+y^2),x = 0..PI, y = 0..PI)
 
 


 
 
 

Curve sketching


In the following session, we use some of the system functions form the previous section to sketch and discuss the curve given by the rational function:
                         f(x) = (x - 1)^2/(x - 2) + a
with a parameter a. First we determine some characteristics of this function.

>>f := x ->((x - 1)^2/(x - 2) + a):
>>singularities := discont(f(x),x)
                                    {2}

The function discont determines the discontinuities of the function f with respect to the variable x.  It returns a set of such points.  Thus the above f is defined and continuous for all x except 2.  MuPAD can determine the limit as x approaches either infinity or negative infinity.

>>limt(f(x), x = 2, Left), limit(f(x), x = 2, Right)

                -infinity, infinity

You find the roots of f by solving the equation f = 0:

>>roots := solve(f(x) = 0,x)
    {                          2   1/2                                             2    1/2                            }
    {           (4 a +  a    )                    a               (4 a +  a   )               a                    }
    {  1 -  -----------------------  -       - -,            -----------------------   --   + 1           }
    {                       2                         2                           2                   2                   }

Depending upon a, either both or none of the two roots are real.  Now we want to find the local extrema of f.  To this end, we determine the roots of the first derivative f ':

>> f'(x)
                                                          2
                            2 x  - 2        (x - 1)
                           ----------   -   ----------
                             x - 2                     2
                                               (x -  2)

>> extrema := solve(f'(x) = 0,x)

                                    {1 , 3}

These are candidates for local extrema.  However, some may be saddle points.  If the second derivative f" does not vanish at these points then both are really extrema.  We check:

>> f ' ' (1), f ' ' (3)

                        -2, 2

Our results imply that f has the following properties:  for any choice of a, there is a point of discontinuity at x = 2, there is a local maximum at x = 1, a local minimum at x = 3

>>maxvalue := f(1); minvalue := f(3)
                                       a
                                    a + 4

We can also determine the limits of f(x) as x tends to -infinity and infinity:

>>limit(f(x),x = -infinity), limit(f(x), x = infinity)
                            -infinity, infinity
 
 
 

Identifiers and Their Values

    Consider:

>> delete x, a: y := a + x
                                    a + x

Since the identifiers a and x only represent themselves, the "value" of y is the symbolic expression a + x. We have to distinguish carefully between the identifier y and its value.  The value of an identifier denotes the MuPAD object that the system computes by evaluation and simplification of the right hand side of the assignment identifier := value is at the time of assignment.

    Note that in the above example the value of is composed of the symbolic identifiers a and x, which may be assigned values  at a later time.  If we assign the value 2 to a, then a is replaced by its value 2 in the expression a + x, and the call returns x + 2:

>>a := 2: y
                                        x + 2

We say that the evaluation of the identifier y returns the result x + 2, but its value is still a + x.

         MuPAD distinguishes between an identifier, its value, and its evaluation: the value denotes the evaluation at the time of assignment, a later evaluation may return a different "current value".

If we assign the value 3 to x, then both andx are replaced by their values in the next evaluation of y:

>>x := 3: y
                                            5

The evaluation of is now 5 but its value is still a + x.

We can delete the values of x and a, and the evaluation of is its original value.

>> delete a, x: y
                                    a + x
 
 
 

Substitution: subs

    All MuPAD objects consist of operands.  An important feature of a computer algebra system is that is can replace these building blocks by new values.  MuPAD provides functions subs, subsex (short for substitute expression), and subsop (short for substitute operand).

    The command subs(object, Old = New) replaces all occurrences of the subexpression Old in object by the value New:

>> f:= a + b*c^b: g := sub(f, b = 2): f, g
                            b              2
                    a + b c   , a + 2 c

You see that subs returns the result of the substitution, but the identifier f remains unchanged.  If you represent a map F by the expression f = F(x), then you may use subs to evaluate the function at some point:

>>f := 1 + x + x^2:
>> subs(f, x = 0), subs(f, x = 1),
      subs(f ,x = 2), subs(f, x = 3)

                        1, 3, 7, 13

The output of the subs command is subjected to the usual simplification of MuPAD's internal simplifier.  In the above example, the call subs( f, x = 0) produces the object 1 + 0 + 0^2, which is automatically simplified to 3.  You must not confuse this with evaluation, where in addition all identifiers in an expression are replaced by their values.

         The function subs performs a substitution.  The system only simplifies the resulting object, but does
         not evaluate it upon return.

In the following example:

>> f := x + sin(x): g := subs(f, x = 0)
                            sin(0)

The identifier sin for the sine function is not replaceed by the corresponding MuPad function, which would return sin(0) = 0.   Only the next call would complete the evaluation:

>> g
                                            0

You can force evaluation by using eval:

>> eval(subs(f , x = 0))
                                            0

You may replace arbitrary MuPAD objects by substitution.  In particular, you can substitute functions or procedures as new values:

>> eval(subs(h, (a + b), h = (x -> (1 + x)^2)))
                                    2
                            (a + h)    + 1
 
 

Differentiation

The call diff(expression x) computes the derivative of the expression relative to the unknown x.

>>diff(sin(x^2), x)
                                                2
                                2 x cos( x   )

If the expression contains symbolic calls to functions whose derivative is not known, the diff returns itself symbolically.

>>diff(x * f(x), x)

                        f(x) + x diff( f(x), x)

You may compute higher derivatives via diff(expression, x, x, ...).This may also be generated by the sequence operator $.
>>diff(sin(x ^ 2), x, x, x) = diff(sin(x^ 2), x $ 3)
                            2           3           2
        - 12 x sin (x   ) - 8 x     cos(x   )  =

                                   2          3          2
                - 12 x sin(x   ) - 8 x   cos(x   )

>>f := (x ->(sin(ln(x))):
     diff(f(x), x)
                        cos(ln (x))
                        -------------
                                x

MuPAD recognizes other forms of the differentiation operator.  The most common are the operators D and '.

>>D(f)(x)
                         cos(ln (x))
                        -------------
                                x
 

>>f'(x)

                        cos(ln (x))
                        -------------
                                x
 

Other examples are the following:

>>D(f)(1), D(f)(y ^ 2), D(g)(0)
                                          2
                            cos(ln(y    )
                cos(0), ---------------, D(g)(0)
                                   2
                                y

>>f'(1), f'(y^2), g'(0)

                                          2
                            cos(ln(y    )
                cos(0), ---------------, D(g)(0)
                                   2
                                y
 
 
 

Integration


The function int features both definite and indefinite integration:

>> int(sin(x), x) , int(sin(x), x = 0..PI/2)

                        -cos(x), 1

If int is unable to compute a result, then it returns itself symbolically.  In the following example, the integrand is split into two terms internally.  Only one of these has an integral that can be represented by elementary functions:

>>int((x - 1)/(x *sqrt(x^3 + 1), x)

        /         1                       \
   int|  -----------------, x        |   +
       |      3       1/2                |
        \ (x   + 1)                    /

       /         3       1/2                        3        1/2   \
       |  (- (x   + 1)        - 1)     (1 - (x    + 1)      )  |
   ln |  ------------------------------------------  |
       |                                 6                               |
        \                             x                                  /
    --------------------------------------------------
                                       3

Compute the following integrals:

>> int(sin(x) * cos(x) , x=0..PI/2)
 

>>int(1/sqrt(1 - x^2), x = 0..1)

>> int(x*arctan(x),x = 0..1)
 

Change of variables

In order to change variable one uses the function intlib::changevar(integral, equation, variable of integration).  The following examples should help you understand the syntax of this operator..  Note the use of the hold operator imbedded in the argument.

>>intlib::changevar(hold(int)(x * exp(x ^ 2),x = 0 ..2),t = x^2, t)
                                              /   exp(t)                          \
                                        int |  ------------- ,  t = 0..4       |
                                              \       2                              /

intlib::changevar will not evaluate the integral.  In order to evaluate the integral, one could use the eval operator:

>>eval(%)
                        exp(4)     -   1
                       --------        --
                            2              2

To find a floating-point approximation one could use:

>>float(%)

                        26.79907502
 

To find a numerical approximation, one could have also used the MuPAD command in the numeric library:

>>numeric::int(x*exp(x^2),x = 0..2)

                         26.79907502
Note that to apply a change of variables, one must use the MuPAD command intlib::changevar which lies in the intlib library of functions.
 
 

Plotting graphs


MuPAD has a many sophisticated graphics packages from which you can control almost all the features you would like on a graph.  You may use the built in help screens to learn about the many advanced features of these packages and the syntax that MuPAD uses.  We will only introduce you to the basic graphics packages the are built in to the MuPAD kernel.
 

2 dimensional plots:

The basic command is plotfunc2d(expression, domain).  For example to plot the parabola f(x) = 3x^2 + x + 1 over the interval [-2, 3] one enters the command:

>>plotfunc2d(3*x^2 + x + 1, x = -2..3)

In a few seconds a new window Vcan open with the graph on the screen.  You can modify the plot by opening up the Object Properties or Scene Properties under the Edit pull-down menu.

This is the Object Properties dialog box.

With the Object Properties and Scene Properties one can add plots to the graph, change the color scheme, the formatting
of the Line Style, the domain of the function, the title of the graph as well as many other things.

To save the graph, use the File pull-down menu.
 

3-dimensional plots:


The basic three dimension command in MuPAD is plotfunc3d(expression, domain).  For example to plot the function

                                                f(x,y)=x^2 + y^2   for x,y in [-2,2]

enter the command
>>plotfunc3d(x^2+y^2,x=-2..2,y=-2..2)

The toolbar and the mouse allow you to redraw the screen from any perspective you would like.  Again the Object Properties  and Scene Properties dialog boxes are available to modify the parameters of the graph.  Saving the graph is the same as for the 2dimensional graphs above.
 

Integration by Parts and by Change of Variables


Integration is the opposite process of differentiation.  Any function F in the variable x whose derivative is f is an integral (antiderivative) of f.  In MuPAD, we would write diff(F, x) = f.

>> f := cos(x)*exp(sin(x))

                                cos(x) exp(sin(x))

>>F : int(f, x)

                                exp(sin(x))

>>diff(F, x)

                                cos(x) exp(sin(x))

    A constant is not added to the integral.  With MuPAD it is possible to determine integrals of elementary functions, of many special functions and restricted algebraic functions.

>> int(sin(x)^4*cos(x), x)
                                                      5
                                            sin(x)
                                           ----------
                                                5

>>int(1/(2 + cos(x)),x)
                              1/2              /            sin(x)          \
                         2 3       arctan |  ------------------------ |
            1/2                                |                    1/2       |
      x  3                                     \  cos(x)  + 3       +2 /
       --------  -  --------------------------------------------------
          3                                    3

>> int(exp(-a*x^2), x)
                                         1/2         1/2
                                    PI       erf(a       x)
                                    ---------------------------
                                                      1/2
                                               2   a

>>int(x^2/sqrt(1-5*x^3),x)
                                             3
                                       2  x
                                       --------  - 2/15
                                            3
                                       -------------------
                                                  3     1/2
                                      (1 - 5 x    )

>>normal(simplify(diff(%,x)
                                                    2
                                                x
                                        -------------------
                                                     3   1/2
                                        (1 - 5  x
 


Help--intlib::byparts

The MuPAD command: intlib::byparts(integral, du) performs integration by parts where the integrand is of the form:
                                         v(x)u'(x) dx

Call(s):

A intlib::byparts(integral, du)

Parameters:

        integral  -- integral: an expression of the type "int" of the form int( du * v, x)
        du         -- the part to be integrated:  an arithmetical expression
 

Return Value:

 An arithmetical expression containing the type "int" or the unevaluated function call.
 

Related Functions:

 subs, intlib::changevar


Details:


               int(u'(x)*v(x), x) = u(x)*v(x) - int(u(x)*v'(x), x)

           and for definite integals as

               int(u'(x)*v(x), x = a..b) = (u(x)*v(x),x = a..b) - int(u(x)*v'(x),x = a..b)
 


Integration by parts and by change of variables

Typical applications for the rule of integration by parts

                    int(u'(x)*v(x), x) = u(x)v(x) - int(u(x)*v'(x),x)
 

are integrals with integrands of the form:  p(x) * cos(x) where p(x) is a polynomial.  Thereby one has to use the rule in the way that the polynomial is differentiated. Thus one has to chose u'(x) = cos(x).

>>intlib::byparts(hold(int)(x - 1)*cos(x), x), cos(x))

                        sin(x)  (x - 1) - int(sin(x), x)

Inparticular when u'(x) = 1 it is possible to compute a lot of well-known standard integrals, like int(arcsin(x), x).

>>intlib::byparts(hold(int)(arcsin(x), x), 1)
 

                                          /           x                \
                x arcsin(x) - int |  ------------------,  x |
                                          |           2   1/2         |
                                          \  (1 - x   )               /

In order to determine the remaining integral one may use the method change of variable with t(x) = 1 - x^2.

>>F := intlib::changevar(hold(int)(x /sqrt(1 - x^2), x), t = 1 - x^2)
                                        /           1          \
                                  int | -   -------------, t |
                                       |                1/2     |
                                       \         2   t          /

Using backsubstitution into the solved integral F one gets the required result:

>> hold(int)(arcsin(x),x) =x*arcsin(x) - subs(eval(F), t = 1 - x^2)
                                                                    2  1/2
        int(arcsin(x), x) = x arcsin(x) + (1 - x   )

Applying change of variables with the integrator is problematic, since it may occur that the integrator will never terminate.  On the other hand this may also lead to the fact the some integrals cannot be solved directly.

>>f := sin(x)*sqrt(1 + sin(x)):
    int(f,x)
                                                              1/2
                            int(sin(x) (sin(x) + 1)      , x)

>>subs(eval(intlib::changevar(hold(int)(f , x),t = sin(x))), t = sin(x))
                                                        1/2  /    2 sin(x)             \
                     (sin(x) - 1)(sin(x) + 1)       | - ------------- + 4/3  |
                                                               \        3                    /
                    --------------------------------------------------------------
                                                          2   1/2
                                          ( 1 - sin(x)  )


Examples of integration by parts

Example 1.  As a first example we apply the rule of integration by parts to the integral int(x * exp(x), x = a..b).  By using the hold function we secure that the first argument is of the "int":

>>intlib::byparts(hold(int)(x * exp(x), x = a.. b), exp(x))

            b exp(b) - a exp(a) - int(exp(x), x = a..b)
In this case u'(x) = exp(x) and v(x) = x.
 

Example 2.  In this advanced example we use integration by parts to evaluate the integral with integrand exp(ax)sin(bx).  To do this we must prevent the integrator from evaluating the integral. Thus we first inactivate the requested integral with the function freeze.

>>F := freeze(int)(exp(a * x)*sin(b * x), x)

                    int (sin(b x) exp(a x), x)

and apply the partial integration with u'(x) = exp(ax):

>>F1 := intlib::byparts(F, exp(a * x))

           sin( b x) exp(a x)           / b cos(b x) exp(a x)    \
           -----------------------  -  int| -------------------------, x |
                        a                        \             a                     /

To this result again we can apply integration by parts.  But to avoid evaluating that integral we have to be very careful.  In order to get it we must use the function level:

>>F2 := -op(level(F1, 1), 2)
                                      / b cos(b x) exp(a x)       \
                                int |  ---------------------------,  x |
                                      \                 a                     /

With that we can now calculate the requested integral:
>>F3 := expand(simplify(op(F1, 1) - intlib::byparts(level(F2, 1), exp(a*x))))
    sin(b x) exp(a x)         b cos(b x) exp(a x)
    ----------------------   -   -------------------------  -
               a                                         2
                                                       a
      2
   b     int(sin(b x) exp(a x), x)
    ------------------------------
                               2
                            a

As we see, both integration by parts steps lead to the same integral but with a different factor.  Therefore we can solve it for the requested integral and we finally get:

>>F = nomal(1/(1 + b^2)/a^2)*_plus(op(level)(F3, 1), [1..2])))
                                                          a sin(b x) exp(a x) - b cos(b x) exp(a x)
                int(sin(b x)exp(a x),x ) = -------------------------------------------------------
                                                                                 2        2
                                                                              a    +  b

Example 3:  Here we demonstrate the difference between indefinite and definite integration by parts.  If in the indefinite case, the partial part cannot be solved, simply the unevaluated integral is plugged inot the integrator rule:

>>intlib::byparts(hold(int)(x*f(x), x), f(x))

            x int(f(x), x) - int(int(f(x), x), x)

This is not true in the definite integral case:

 >>intlib::byparts(hold(int)(x *f(x),x),x = a..b),f(x))

Warning no closed form for int(f(x),x)[intlib::byparts]
    intlib::byparts(int(x* f(x),x = a..b),(f))

Help--intlib::changevar

intlib::changevar(integral, eq, ..) performs a change of variables for indefinite and definite integrals.
Call(s):
    A intlib::changevar(integral, eq <, var>)
Parameters
    integral --integral:  an expression of type "int"
    eq        --equation defining the new integration variable in terms of the old
                   one, an equation
    var       -- new integraation variable:  an identifier
Return Value:  an expression of type "int"

Related Functions:  subs, intlib::byparts
 

See examples