Skip to main content
gamedev.net
🔒 Locked

[java] Calculus

Started by samoz Feb 13, 2007 at 10:34 AM 4 replies 1.7k views
Original Post
samoz
samoz
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?
Sneftel
Sneftel
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.)
Alrecenk
Alrecenk
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;tsum+=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
PorkBag
PorkBag
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.
Ultimape
Ultimape
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.