Hello guys. I'm trying to make a bisection method in my program I keep getting an error that tells me that I can't reference that method because I can't access a non-static method bisection can't be referenced from a static context. That basically means that I can't access the method unless I make my arrays static but that changes the values from within as well. Its easier to explain if you try running it and changing the accessibility. Also, I don;t know if I'm even doing the Bisection method right or not. I've spent days on this program, is there something I can do to fix this without starting all over?

import java.util.Scanner; public class Polynomial { int [] coefficients = new int[3]; int [] powers = new int[3]; public static void main(String[] args) { int c1, c2, c3; Scanner input = new Scanner(System.in); /*for(int i = 0; i<coefficents.length-1;i++) { } */ Polynomial P1 = new Polynomial(4, 5, -3, 3, 1, 0); Polynomial P2 = new Polynomial(1, 1, -2, 3, 1, 0); System.out.println("Here is the Polynomial 1: " + P1); System.out.println("Here is the Polynomial 2: " + P2); System.out.println("P1 eval = " + P1.evalAt(-1)); System.out.println("P2 eval = " + P2.evalAt(1)); System.out.println("Bisection " + bisection(P1, P2)); System.out.println("================================================"); P1.derivative(); System.out.println("Here is the Derivative for P1: " + P1); P2.derivative(); System.out.println("Here is the Derivative for P2: " + P2); } Polynomial(int a, int b, int c, int x, int y, int z) { coefficients[0] = a; coefficients[1] = b; coefficients[2] = c; powers[0] = x; powers[1] = y; powers[2] = z; } public static int evalAt(int x) { int sum = 0; for(int i = coefficients.length-1; i>=0;i--) { sum = coefficients[i] + x * sum; //System.out.print(sum + "\t"); } return sum; } public void derivative() // Evaluates the Derivative { for(int i = 0; i<=2;i++) { coefficients[i] = powers[i] * coefficients[i]; powers[i]--; } } public double bisection(Polynomial a, Polynomial b) { double tolerance = 0.000001; double m, ya, yb; double result = 0; int i = 0; double A = a.evalAt(1); double B = b.evalAt(2); while( B-A > tolerance) { m = (A+B)/2; ya = m * m - coefficients[2]; yb = A * A - coefficients[2]; if(ya > 0 && ya < 0 || yb <0 && yb > 0 ) { B = m; } else { A = m; } System.out.println((A+B)/2); } result = (A+B)/2; return result; } public String toString() { String s = ""; for(int i=0;i<coefficients.length;i++) { if(powers[i]==0) { s = s + "+" + coefficients[i]; } else if(powers[i]>0) s = s + "+" + (coefficients[i]); else if(powers[i]<0) { s = s + "-" + (-coefficients[i]); } if(i == 1) s = s + "x^" + powers[i]; else if(i > 1) s = s + "x^" + powers[i]; //else if(i == coefficients.length-1) else s = coefficients[i] + "x^" + powers[i]; } return s; } }

Sample:

Polynomial.java:31: error: non-static method bisection(Polynomial,Polynomial) cannot be referenced from a static context System.out.println("Bisection " + bisection(P1, P2)); ^ Polynomial.java:59: error: non-static variable coefficients cannot be referenced from a static context for(int i = coefficients.length-1; i>=0;i--) ^ Polynomial.java:61: error: non-static variable coefficients cannot be referenced from a static context sum = coefficients[i] + x * sum; ^ 3 errors