I am creating a project to compute roots for bisection method in JSwing. There are errors when obtaining function from the user, put it in a method and returning it.
I have tried various way that I know of but it wasnt successful such as converting the string to double, initialised the obtained function before returning it and a few more.
public double f(double x) {
double func =Double.parseDouble(textFunction.getText());
return func;
}
public void bisection_method(double x1,double x2) {
double error = Double.valueOf(textError.getText());
int n = 0;
if(f(x1) * f(x2)>0.0)
JOptionPane.showMessageDialog(null, "Function has same signs at ends of interval");
while(Math.abs(x1 - x2) >= error) {
double m = (x1 + x2) / 2.0;
if(f(m) * f(x1) < 0.0) {
x2 = m;
n++;
} else {
x1 = m;
n++;
}
System.out.println(m);
}
}
I expect the roots of equation to show but nothing happens.