Tutorial:JMathLab/Indefinite Integrals

From HandWiki

Indefinite Integral

integrate(function, x) integrates a function with respect to the symbolic variable x. The program recognizes all built-in functions and polynomials:


<jc lang="math"> syms x a=integrate(x^2+x-3,x) printf('%f',a) </jc>

Let us consider an example which shows the original function and its integral in a single 2D plot:

<jc lang="math"> syms x w1=x^2+x w2=integrate(w1,x) plot2d() draw2d(w1,'name=x^{2}+x') draw2d(w2,'name=integral;linestyle=2;color=blue;') </jc>

All trigonometric functions are also supported. Run this script to see the answer.

<jc lang="math"> syms x y=integrate(cos(x)*sin(x),x) printf('%f',y) </jc>

If function is rational (i.e. quotient of two polynomials, whose coefficients do not depend on x)) we use the standard approach: Separate a polynomial part, then separate a square free part using Horowitz' [11] method, and finally integrate the rest using partial fractions. The final terms are collected to avoid complex expressions.

<jc lang="math"> syms x y=(x^3+2*x^2-x+1)/((x+i)*(x-i)*(x+3)) printf('%f',y) </jc>

<jc lang="math"> syms x y = (x^3+2*x^2-x+1)/(x^3+3*x^2+x+3) a=integrate(y,x) printf('%f',a) b=diff(a,x)  % control printf('%f',b) </jc>

Expressions of type [math]\displaystyle{ g(f(x))\cdot f'(x) }[/math] and [math]\displaystyle{ f'(x) / f(x)} }[/math] are detected:

<jc lang="math"> syms x y=integrate(x*exp(-2*x^2),x) printf('%f',y) </jc>

<jc lang="math"> syms x y=integrate(exp(x)/(3+exp(x)),x) printf('%f',y) </jc>

Substitutions of type $(a\cdot x+b)$ are applied:

<jc lang="math"> syms x y=integrate(3*sin(2*x-4),x) printf('%f',y) </jc>

Products polynomial(x)*f(x) are fed through partial integration. This solves all cases where $f$ is one of exp, sin , cos , log , atan.

<jc lang="math"> syms x y=integrate(x^3*exp(-2*x),x) printf('%f',y) </jc>

<jc lang="math"> syms x y=integrate(x^2*log(x),x) printf('%f',y) </jc>

All trig and exp-functions are normalized. This solves any expression, which is the product of any number and any type of exponentials and trigonometric functions, and some cases of rational expressions of trig- and exp-functions

<jc lang="math"> syms x y=integrate(sin(x)*cos(3*x)^2,x) printf('%f',y) </jc>

<jc lang="math"> syms x y=integrate(1/(sin(3*x)+1),x) printf('%f',y) </jc>

The special case $\sqrt{ax^2+bx+c}$ is implemented:

<jc lang="math"> syms x y=integrate(sqrt(x^2-1),x) printf('%f',y) </jc>

Clever substitutions may be supplied manually through subst(). If all fails, integrate numerically using quad or romberg.