The assignment is to:
- Create the java statement that will produce f(x) = 2x3 - 8x2 + x + 16.
- Write a Java program that will find the extrema (both high and low) for the function in part 1 across the closed interval (-1, 3).
I don't know what I am doing wrong here exactly but I am getting an infinite number of 9.09.09 and so on.
import java.util.*;
import java.math.*;
public class Extrema
{
public static void main(String[] args)
{
double step = 0.00001;
double x = -1.0;
double xn = 3;
double highest = calc(x);
while (x <= xn)
{
double f = calc(x);
if (f > highest)
{
highest = f;
}
step++;
System.out.print(highest);
}
}
public static double calc(double x)
{
double f = 2*Math.pow(x, 1/3) - 8*Math.pow(x, 2) + x + 16;
return f;
}
}