Contents

Symbolic Integration - First Examples


On this page we consider indefinite integrals. See also Definite Integrals.

Maxima can compute indefinite integrals of many functions. Symbolic Integration describes the algorithm for computing indefinite integrals.

integrate(x/(x^3 + 1), x);
					2 x - 1
		      2		   atan(-------)
		 log(x  - x + 1)        sqrt(3)	   log(x + 1)
      		 --------------- + ------------- - ----------
			6	      sqrt(3)	       3

To verify this result, we compute its derivative:

diff(%, x);
			2	        2 x - 1		  1
     	        ------------------ + -------------- - ---------
			    2		 2	      3 (x + 1)
		   (2 x - 1)	     6 (x  - x + 1)
		3 (---------- + 1)
		       3

This is a sum of three rational expressions. Obviously, every term of the integral contributes one rational expression. We use ratsimp to bring all three expressions on a common denominator:

ratsimp(%);
	      x
      	    ------
	     3
	    x  + 1

Let us look at an example with trigonometric functions and exponentials:

 integrate(exp(a*x)*sin(x)*cos(x), x) ;

We obtain:

			  a x
			%e    (a sin(2 x) - 2 cos(2 x))
(%o1)		        -------------------------------
				      2
				  2 (a  + 4)

To verify the result, we compute the derivative:

(%i2) diff(%, x);
	 a x				   a x
     a %e    (a sin(2 x) - 2 cos(2 x))	 %e    (4 sin(2 x) + 2 a cos(2 x))
(%o2)--------------------------------- + ---------------------------------
		    2				        2
		2 (a  + 4)			    2 (a  + 4)

This answer is a surprise, but simplification gives

ratsimp(%);
				  a x
				%e    sin(2 x)
(%o3)			        --------------
				      2

To get rid of the sinus of the multiple angle, we apply trigexpand:

trigexpand(%);
				a x
(%o4)			      %e    cos(x) sin(x)

Sometimes Maxima answers the so-called 'noun form' of an integral. This tells you that Maxima was unable to find an integral:

integrate(1/((x-3)^4+1/2), x);
			       /
			       [      1
(%o5) 			       I ------------ dx
			       ]        4   1
			       / (x - 3)  + -
					    2

Sometimes a change of the integration variable helps:

changevar (%, x - 3 - y ,y ,x);
				      /
				      [	   1
(%o6) 				    2 I -------- dy
				      ]	   4
				      / 2 y  + 1

Now we can integrate:

ev (%, integrate);

and obtain.

		      2	   3/4			     2	  3/4
	 log(sqrt(2) y  + 2    y + 1)   log(sqrt(2) y  - 2    y + 1)
(%o8) 2 (---------------------------- - ----------------------------
		       3/4			      3/4
		    4 2				   4 2

							3/4			   3/4
					 2 sqrt(2) y + 2	    2 sqrt(2) y - 2
				    atan(------------------)   atan(------------------)
						 3/4			    3/4
						2			   2
				  + ------------------------ + ------------------------)
						3/4			   3/4
					     2 2		        2 2

Backsubstitution gives us the desired integral.

sfx: %, y=x-3;
			    2	 3/4
	 log(sqrt(2) (x - 3)  + 2    (x - 3) + 1)
(%o8) 2 (----------------------------------------
			     3/4
			  4 2

									3/4
						   2 sqrt(2) (x - 3) + 2
					      atan(------------------------)
		      2	   3/4				      3/4
   log(sqrt(2) (x - 3)  - 2    (x - 3) + 1)		     2
 - ---------------------------------------- + ------------------------------
		       3/4				     3/4
		    4 2					  2 2

			     3/4
	2 sqrt(2) (x - 3) - 2
   atan(------------------------)
		   3/4
		  2
 + ------------------------------)
		  3/4
	       2 2

The integrand is an everywhere positive function. For such functions we can evaluate the integral at the limits of a definite integral to obtain its value. To compute:

'integrate(1/((x-3)^4+1/2), x,0, 1);
					 1
					/
					[       1
(%o17) 				        I  ------------ dx
					]	  4   1
					/  (x - 3)  + -
					 0	      2

we can write:

ratsimp(subst (1, x, sfx) - subst(0, x, sfx));

This expression uses substitution to evaluate the indefinite integral at the limits of the definite integral. We obtain:

		     3/4			     3/4
	   1/4	    2    + 6 sqrt(2)	   1/4	    2    + 4 sqrt(2)
(%o14) (2 2    atan(----------------) - 2 2    atan(----------------)
			   3/4				   3/4
			  2				  2

    1/4	       3/4		       1/4	  3/4
 + 2    log(3 2	   + 9 sqrt(2) + 1) - 2	   log(2 2    + 4 sqrt(2) + 1)

    1/4		 3/4			 1/4	      3/4
 + 2    log(- 2 2    + 4 sqrt(2) + 1) - 2    log(- 3 2	  + 9 sqrt(2) + 1)

			    3/4				    3/4
      1/4      6 sqrt(2) - 2	      1/4      4 sqrt(2) - 2
 + 2 2	  atan(----------------) - 2 2	  atan(----------------))/4
		      3/4			      3/4
		     2				     2

The numerical value is:

(%i15) float(%);
(%o15) 			       0.02880633385274

Numerical integration with the Romberg method confirms that result:

(%i16) romberg(1/((x-3)^4+1/2), x,0, 1);
(%o16) 			       0.02880633392455

The following example shows how an integrand of the form f(x)*f'(x) is handled:

p: (x^3 + x^2)^2*(3*x^2 + 2*x);
				2	   3    2 2
(%o4)			    (3 x  + 2 x) (x  + x )
p2: expand(p);
			      8	     7	    6	   5
(%o5)			   3 x  + 8 x  + 7 x  + 2 x
integrate(p2*sin(2*x^3 + 2*x^2)*cos(x^3 + x^2),x);

We obtain:

	  3	 2	   3	  2	     6	     5	    4
(%o6)((6 x  + 6 x ) sin(3 x  + 3 x ) + (- 9 x  - 18 x  - 9 x  + 2)

	3      2	 3	 2	 3    2
 cos(3 x  + 3 x ) + (54 x  + 54 x ) sin(x  + x )

	  6	  5	  4	       3    2
 + (- 27 x  - 54 x  - 27 x  + 54) cos(x  + x ))/54

Integrands with Simple Radical Extensions

The following integral can be computed

integrate((-4*x^3*(x^4 + 1)^(2/3)
           -16*x^3*(x^4 + 1)^(1/3))
     /(3*x^8 +6*x^4 + 3), x);

We obtain:

				1	      2
(%o2)			   ----------- + -----------
			     4	   1/3	   4	 2/3
			   (x  + 1)	 (x  + 1)

Simplification with ratsimp gives:

			    4	  2/3	    4	  1/3
			  (x  + 1)    + 2 (x  + 1)
(%o3)			  ---------------------------
				     4
				    x  + 1

A sightly more complicated integral is solved in terms of exponentials and logarithms:

integrate(((6*x^5 + 7*x^4 - 36*x^3 + 18*x - 21)*(x^4 + 1)^(2/3)
           + (2*x^6 - 20*x^4 - 40*x^3 + 18*x^2 + 12)*(x^4 + 1)^(1/3))
     /(3*x^8 +6*x^4 + 3), x);
				 4				  4
			  2 log(x  + 1)			     log(x  + 1)
			  -------------			     -----------
	   2		        3	      3			  3
       (3 x  - 7 x + 9) %e	        + (2 x  + 4 x + 5) %e
(%o4)  -----------------------------------------------------------------
				     4
				    x  + 1

We have to use radcan to obtain a canonical representation of the radicals:

radcan(%);
	      2		     4	   2/3	     3		    4	  1/3
	  (3 x  - 7 x + 9) (x  + 1)    + (2 x  + 4 x + 5) (x  + 1)
(%o5)	  -----------------------------------------------------------
				     4
				    x  + 1

**

(%i6) integrate (7*tan(x)^8 + 7*tan(x)^6, x);
	       7	    5		 3
	 15 tan (x) - 21 tan (x) + 35 tan (x) - 105 tan(x)
(%o6) 7 (------------------------------------------------- + x)
				105

					      5		  3
					 3 tan (x) - 5 tan (x) + 15 tan(x)
				    + 7 (--------------------------------- - x)
							15
(%i7) ratsimp(%);
				       7
(%o7) 				    tan (x)

a definite integral:




Contents