how do i display a line graph that have n (x, y) data plotted and a line drawn on it provided the an equation of y = ax^3 + bx^2 + cx^1 + d, given the coefficients a,b,c,d. preferably in jpanel..
cool, that's what i needed. ok... i got the graph part sorted out, but there's just this small problem.... i need to display a polynomial eqn line for each generation, how do i destroy the line for the generation b4? and since my program will run for many generation, how do i display the lines on the graph one by one without having all at one go? it seems that my program will keep running and running until it stops, then only the lines(in this case all the lines) are displayed.
i cut out most of the spinner and selection coding as i only need the graph.. here.. i'll explain waht i'm doing, i writing genetic algorithm to fit a curve, u do know what GA is right? well.. just in case, genetic algorithm works in a way that it will produce a whole set of random equations(by random generating sets of coefficients), called the population. then this population of coefficient sets will go through some operations... each time it goes through these operation, a new population will be form from the old one.. so i will have new lines everytime... going through the operations once is call one generation... so there will be tons of generations before the lines evolve themselves into better ones.. what i want is, for each generation, i want to get the best fitted line to display on the screen... but everytime i run the program... it keep evolving the population(which keeps the pc busy) and dun have time to display the graphs. it will only show the graph but no lines are produced as the algorithm is working too fast and repaiting is too slow. this is what's left of the code, and i called the setConstant() when one generation is done in the algorithm import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.text.*; import javax.swing.*; import javax.swing.event.*;
/** * * @author TAN */ class Graph extends JPanel { final int PAD = 15; NumberFormat nf; double[] no = new double[4]; double a, b, c, d; public Graph() {