# [java] Calculus

This topic is 4310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys, I was doing some Java work the other day and I was wondering, is there any way to incorporate calculus based math using default classes (such as Math)? Something like solving integrals over ranges or something like that . . . Or even logarithms? Because I can't find logarithms in Math . . . Or do you guys use a 3rd party class for your upper level math needs?

##### Share on other sites
Well, the math class certainly does have log(). In terms of solving integrals, it doesn't explicitly have numerical integration and differentiation, but it has everything you need to implement it yourself using Taylor expansions and Runge-Kutta. (In fact, for those you don't even really need java.lang.Math; standard arithmetic functions are sufficient.)

##### Share on other sites
There is also a Math.pow(double number, double exponent) and a Math.exp(double x) that calculates e^x. If you want to approximate derivitaves it's very easy just use (f(x+h)-f(x-h))/(2h) where h is some really small number that's not zero(maybe 0.00000001 depending on how much accuracy you need). If you want to find a definite integral you can use the sum definition though if you need alot of accuracy it's not very fast(but it is very straight-forward)

//integral of f(x) from a to b
double t,h=0.0000001 ;
double sum=0;
for(t=a;t<b;t+=h){
sum+=f(t)*h ;
}

It may also be worth noting that all logarithms can be done with one log function and Math.log is the natural log.

http://java.sun.com/j2se/1.3/docs/api/java/lang/Math.html

##### Share on other sites
Also there are several different methods of calculating an integral, like the trapezoid method, which should be more accurate. A search for "numerical integration" should explain things in more detail.

##### Share on other sites
What about something akin to the ti89... can't they calculate derivitives and intergrals based on manipulating the math symbols, vs pure caclulations?

Are there librarys for that?

##### Share on other sites
Quote:
 Original post by UltimapeAre there librarys for that?

There seems to be at least one, but I haven't used it. It was just the second (though linked from the first) result of a quick google search.

-jouley

1. 1
2. 2
Rutin
23
3. 3
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 11
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013158
×