Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Attempting a graph program

Hi, I'm trying to create this program that graphs a y= equation onto a graph, but I can't seem to get the equation that processes the original equation into Java compatible coordinate points correct...

Here's the code portion (won't upload entire program b/c it's a bit too big):

System.out.println ("y= ax^3 + bx^2 + cx + d");

//asks user for y= values
System.out.print ("a:");
double a = reader.nextDouble();
System.out.print ("b:");
double b = reader.nextDouble();
System.out.print ("c:");
double c = reader.nextDouble();
System.out.print ("d:");
double d = reader.nextDouble();

g.drawLine(0, 200, 400, 200);
g.drawLine(200, 0, 200, 400);
//draws the x and y axis, respectively

// problem area begins: (graphs the function)
for (int z = 0; z < 400; z++){
y1 = (int)(-Math.pow(a*(z-200)/10, 3) + -Math.pow(b*(z-200), 2) + -c*(z-200) + (-d*10+200));
y2 = (int)(-Math.pow(a*(z-199)/10, 3) + -Math.pow(b*(z-199), 2) + -c*(z-199) + (-d*10+200));

g.drawLine(z, y1, z+1, y2);
//problem area end

This won't compile, because it's only a part of my program.

SO here's the premise of my program to help:
- The area that the graph is to be drawn is a 400*400 pixel JFrame
- The graph's boundaries are: x: (-20,20) y: (-20,20)
- That means with a 400 pixel length, 10 pixels will represent an interval of 1
- Because of that, I assume that the equation to find the y value should be divided by 10. However, this only works with y = ax^3 and not more complex equations such as y = ax^3 + bx^2 ... etc.

Assistance pls?

Comments

Sign In or Register to comment.