Hi everybody,
I am new to Java, and can't figure out why my program is not recognizing the class Picture. The program compiles, but when I run it, it gives an error:
Exception in thread "main" java.lang.NoClassDefFoundError: Picture
at NewtonReal.main(NewtonReal.java:55)
Please note that to run NewtonReal, you must include three command-line arguments, such as -20 40 20.
Thanks in advance if you can help.
Here's the code:
import java.awt.*;
public class NewtonReal {
/**
* Executes Newton's method on the function x*x*x-1, until either
* max iterations have occurred or the current guess changes by
* less than eps.
*
* @param x0 initial guess for a cube root of 1
* @param max maximum number of iterations before stopping
* @param eps "epsilon" tolerance: when guess changes by less than
* eps, assume it has stabilized
* @return the number of iterations executed
*/
public static int newton(double x0, int max, double eps) {
double xnew = 0;
int numIter = 0;
while (numIter < max){
numIter++;
if (3*x0*x0 == 0){
return 0;
}
xnew = x0 - (x0*x0*x0-1)/(3*x0*x0);
if (Math.abs(xnew - x0) < eps){
return numIter;
}
x0 = xnew;
}
return numIter;
}
public static void main(String[] args) {
double X_MIN = Double.parseDouble(args[0]);
double X_WIDTH = Double.parseDouble(args[1]);
int MAX_ITER = Integer.parseInt(args[2]);
int PX_HEIGHT = 512;
int PX_WIDTH = 512;
double Y_HEIGHT = 40;
double EPS = 1.0e-6;
double X_MAX = X_MIN + X_WIDTH;
double x = X_MIN;
double xStep = (double)(X_WIDTH / PX_WIDTH);
double yStep = (double)(Y_HEIGHT / PX_HEIGHT);
Picture pic = new Picture(PX_WIDTH, PX_HEIGHT);
while (x < X_MAX){
int numIter = newton(x, MAX_ITER, EPS);
double xCord = Math.ceil((double)(0 - X_MIN)/X_WIDTH*PX_WIDTH);
double yCord = Math.ceil(511 - (double)(numIter/Y_HEIGHT)*512);
int i = (int)xCord;
int j = (int)yCord;
pic.set(i,j,Color.RED);
x = x + xStep;
}
pic.show();
}
}