Jump to content
  • Advertisement
Sign in to follow this  
samoz

[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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!