views:

123

answers:

4

I am writing a program in java that models a carnot engine and I want to calculate the work done and I need to use integration. I have been looking around on google and haven't found quite what I am looking for, have any suggestions?

+2  A: 

Look at Object-Oriented Implemenation of Numerical Methods, by Didier H Besset.

http://www.amazon.com/Object-Oriented-Implementation-Numerical-Methods-Introduction/dp/1558606793/ref=sr_1_1?ie=UTF8&s=books&qid=1260512473&sr=8-1

There are various equations you can use, depending on what you need, precisely.

James Black
+2  A: 

Look into numerical integration. The general approach is to sample your integrand at various points within the integration interval, then approximate the integral with a weighted sum of the samples - think Riemann sum. There are many different quadrature rules, with different sampling distributions and weighting functions that are best suited to different types of integrands.

Most of the uniform-width quadrature rules (eg. midpoint rule) are very simple and shouldn't take much work to code, but may require far too many samples for acceptable accuracy. Variable-width sampling rules such as Gauss-Hermite are quite a bit more complex, but require far fewer samples for the same level of accuracy, assuming the integrand is sufficiently smooth. You'll have to read about the various rules and figure out what best fits your needs.

I recommend the book Numerical Recipes, which covers numerical integration methods (and just about every other topic in scientific computing) extensively.

Donnie DeBoer
+2  A: 

You have to use an external library, like this one or this other one. You cannot do that with just native methods (well, unless you implement the integration algorithm yourself like the others answers suggest, which I think it's not what you want - otherwise you weren't asking here :-)

Davide
+4  A: 

Apache Commons Math contains ready implementations for integration and much more.

Java Number Cruncher is a good book if you want to do it yourself.

Joonas Pulakka