Go to CCP Homepage

Go to Materials Page

Go to Integral Calculus Materials

Go to Table of Contents

Go Back One Page

Go Forward One Page

MATLAB Tutor

Part 9: Integration

MATLAB can find both an indefinite integral (i.e., antiderivative) and a definite integral of a symbolic expression. That assumes an elementary antiderivative exists. If not, MATLAB can compute a very accurate numerical approximation to the definite integral.

  1. First we calculate indefinite integrals. Before doing anything, we must declare x to be a symbolic variable.   Enter:

    syms x

    Then enter

    int(x*sin(x), x)

    Check that the result is an antiderivative of x sin(x) by entering:

    diff(ans, x)


  2. Introduce another symbolic variable a to investigate how MATLAB deals with more than one symbolic variable in integration. Enter:

    syms a

    Then enter

    int(a*sin(x), x)

    Now enter

    int(a*sin(x), a)

    What is the role of the variable following the comma?


  3. Now try to find an antiderivative for sin ( x5 + x3 ).

    MATLAB does not know an antiderivative of this function that can be defined in terms of functions known to MATLAB. On the other hand, enter:

    int(sin(x^2), x)

    The Fresnel S function is known to MATLAB, but probably not to you. However, you can check by differentiation that the expression is an antiderivative.


  4. Next we calculate definite integrals. To integrate x sin(x) over the interval [0,pi/2], enter:

    int(x*sin(x), x, 0, pi/2)


  5. Now try this method on the integral of sin ( x5 + x3 ) over the interval [0,pi/2].

    MATLAB still doesn't know an antiderivative for this function. To obtain a numerical estimate, enter:

    double( int(sin(x^5 + x^3), x, 0, pi/2) )


  6. If you know that all you want is a numerical estimate, you can use MATLAB's numerical integrator called quadl. (The last character is the letter "el".) No symbolics are involved. Enter:

    f=inline('sin(x^5+x^3)')
    quadl(f , 0, pi/2 )


    Numerical integration also works with user-defined functions in m-files. Symbolic integration doesn't. If you still have the m-file called fun.m that you created in Part 6 of this Tutorial, enter:

    quadl('fun', 0, pi/2 )

    The significance of using the quadl function is that MATLAB does not try to find a symbolic solution before starting on the numerical estimate.


  7. Use MATLAB to find the exact value of each of the following integrals. (Type inf for the infinity symbol.)

    • The integral of 1/(1+x2) from 0 to 1,

    • The integral of 1/(1+x2) from 0 to Infinity,

    • The integral of 1/(1+x4) from 0 to Infinity.


Go to CCP Homepage

Go to Materials Page

Go to Integral Calculus Materials

Go to Table of Contents

Go Back One Page

Go Forward One Page


modules@math.duke.edu

Copyright CCP and the author(s), 1998, 1999, 2000