I am working on a little program to calculate and draw a parabola. But I'm stuck at a little part in the program where I need to calculate the valuetable.
The quadratic function is the following one: y = a * (x - alpha)² + Beta.
So if I fill in the following values for this function: y = 2 * (x - 1)² + (-12). I need to become this value table:
x | -4.0 | -3.0 | -2.0 | -1.0 | 0.0 | 1.0 | 2.0 | 3.0 | 4.0 |
y | 38.0 | 20.0 | 6.0 | -4.0 |-10.0|-12.0|-10.0|-4.0 | 6.0 |
I managed to get the first row right, but the second row (the one that calculates te values), is totally wrong.
public double[][] berekenWaardentabel(int input[], int AANTALKOLOMMEN, double startWaarde) {
double[][] waarden = new double[RIJEN][AANTALKOLOMMEN];
System.out.println(waarden.length);
System.out.println(startWaarde + "\n");
for(int i = 0; i < RIJEN; i++) {
for(int j = 0; j < AANTALKOLOMMEN; j++) {
waarden[0][j] = startWaarde++; //value of first row (start from -4.0, counts upwards)
waarden[1][j] = input[0] * (Math.pow((startWaarde - input[1]), 2)) + input[2];
System.out.print(waarden[i][j] + " ");
}
System.out.println();
}
return waarden;
}
This is the output I get:
-4.0 -3.0 -2.0 -1.0 0.0 1.0 2.0 3.0 4.0 5.0 6.0
86.0 | 116.0 | 150.0 | 188.0 | 230.0 | 276.0 | 326.0 | 380.0 | 438.0 | 500.0 | 566.0
Anyone an idea how to solve this problem? Thanks!