View Full Version : Dealing With Mathmatical Functions In Java
JustnK101
09-30-2005, 06:44 AM
Is there a variable type function in java? I need to be able to deal with functions like matlab does. For example:
function x = "X^2";
Then evauluate the function at a point, for example:
x(10);
is this possible?
What's wrong with doing:
public double f(double x) {
return x*x;
}
System.out.println(f(10));
?
JustnK101
09-30-2005, 08:18 AM
Because I have more complicated functions... But actually I don't need to be able to do that, I will just hardcode the function, but a more important question and something i need to be able to do is operations like:
double sinResult = sin(a);
float powResult = pow(sinResult , 2);
float p1 = 1 + powResult;
sinResult = sin(p1);
powResult = pow(sinResult, 2);
float p2 = 1 + powResult;
I am getting parse errors. Can I not plug variables into the math functions? If not, then how the heck am I suppose to do stuff like this?
JustnK101
09-30-2005, 08:42 AM
What the hell is wrong with java math? I cant even get the following to work.
import java.lang.Math;
class assignment3
{
public void steffensens(double a, int b) {
int i = 1;
while(i <= b)
{
System.out.println(sin(a));
i++;
}
}
public assignment3() {
steffensens(1.0, 5);
}
public static void main(String[] args) {
new assignment3();
}
}
change sin(a) to Math.sin(a)
http://java.sun.com/j2se/1.4.2/docs/api/
search for the MATH class
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.