private void doCurrentMethodStep() { switch (type) { case 0: // bisectiei if (Math.abs(function.evaluate((Cn.lastElement()).x)) < err) { complete = true; theTimer.stop(); } else if (function.evaluate((An.lastElement()).x) * function.evaluate((Cn.lastElement()).x) < 0) { Bn.add(Cn.lastElement()); Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0)); } else { An.add(Cn.lastElement()); Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0)); } break; case 1: // coardei { double evn = function.evaluate((An.lastElement()).x); if (Math.abs(evn) < err) { complete = true; theTimer.stop(); } else { double ev0 = function.evaluate((An.firstElement()).x); double newVal = (An.firstElement().x * evn - An.lastElement().x * ev0) / (evn - ev0); An.add(new PointDP(newVal, 0.0)); } } break; case 2: // secantei { double exn = function.evaluate((An.lastElement()).x); if (Math.abs(exn) < err) { complete = true; theTimer.stop(); } else { double exn1 = function.evaluate((An.elementAt(An.size() - 2)).x); double newVal = (An.elementAt(An.size() - 2).x * exn - (An.lastElement()).x * exn1) / (exn - exn1); An.add(new PointDP(newVal, 0.0)); } } break; case 3: // newton double xn = An.lastElement().x; if (Math.abs(function.evaluate(xn)) < err) { complete = true; theTimer.stop(); } An.add(new PointDP(xn - function.evaluate(xn) / function.evaluate_1(xn), 0.0)); break; } }
public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setStroke(new BasicStroke(1.0f)); if (isOpaque()) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); } g2d.setColor(Color.black); g2d.drawLine(0, frameHeight / 2, frameWidth, frameHeight / 2); g2d.drawLine(frameWidth / 2, 0, frameWidth / 2, frameHeight); for (int i = unityX; i < frameWidth / 2; i += unityX) { g2d.drawLine( frameWidth / 2 + i, frameHeight / 2 - 3, frameWidth / 2 + i, frameHeight / 2 + 3); g2d.drawLine( frameWidth / 2 - i, frameHeight / 2 - 3, frameWidth / 2 - i, frameHeight / 2 + 3); } for (int i = unityY; i < frameHeight / 2; i += unityY) { g2d.drawLine( frameWidth / 2 - 3, frameHeight / 2 + i, frameWidth / 2 + 3, frameHeight / 2 + i); g2d.drawLine( frameWidth / 2 - 3, frameHeight / 2 - i, frameWidth / 2 + 3, frameHeight / 2 - i); } g2d.setColor(Color.blue); function.drawFunctionToGraphic(g2d, frameWidth, frameHeight, unityX, unityY); paintCurrentMethodState(g2d); g2d.dispose(); }