# DMelt:Numeric/5 Integration

# Integration

Use DataMelt to perform numeric integration. DataMelt contains several Java libraries to do this.

- Apache Common math - Apache common math library
- Jas integration - Jas integration package for rational functions

In addition to the above, DataMelt has several classes to perform integration. They are based on jhplot.F1D class. Let us give a small example showing how to integrate [math]cos(x)^3[/math] using a trapezium rule. We will integrate this function between 1 and 10 using 10k iterations.

```
from jhplot import F1D
f1=F1D('cos(x)^3')
print f1.integral(10000,1,10)
```

The output is "-1.13321491381".

Let us perform integration of a function [math]\sin(1.0/x)*x^2+10*\cos(x)^3[/math] using 5 alternative methods: Gauss4, Gauss8, Richardson, Simpson, Trapezium. The code that does a benchmark of all 5 methods is given below:

No access to this part. Use Member area to request membership. If you are already a member, login to Member area and come back to this wiki. |

The output of the above code is:

```
gauss4 = 49.1203116758 time (ms)= 155.088374
gauss8 = 49.1203116758 time (ms)= 57.245523
richardson = 49.1203116758 time (ms)= 53.369496
simpson = 49.1203116758 time (ms)= 27.088362
trapezium = 49.1203116663 time (ms)= 20.023047
```

# Integrating rational functions

The Jas integration package allows integration of rational functions.

Thus, a function is called rational if it is written as $A(x)/B(x)$, where A and B are polynomials. In this section we will show how to integrate rational functions symbolically.

No access to this part. Use Member area to request membership. If you are already a member, login to Member area and come back to this wiki. |

The answer is:

```
A=x^7 - 24 x^4 - 4 x^2 + 8 x - 8
B=x^8 + 6 x^6 + 12 x^4 + 8 x^2
Result: [1 , x, 6 x, x^4 + 4 x^2 + 4 , ( -1 ) x + 3 , x^2 + 2 ] , [0, 1 , x]
```

More information on this topic is in DMelt books |