// PolynomNullstellen.java MM 2012 import Tools.IO.*; // Eingaben /** * Nullstellenberechner für Polynome. */ public class PolynomNullstellen { /** * Hauptprogramm, * startet Dialog zwischen Nutzer und Programm. */ public static void main( String[] args) { // Ueberschrift System.out.println(); System.out.println( "Polynomnullstellen"); // Dialog char weiter = 'j'; do { // Neues Polynom Polynom polynom = new Polynom(); polynom.konsolenEingabe(); // Polynomausgabe System.out.println(); System.out.println( "p( x) = " + polynom); do { // Eingabe der Startnullstelle double x0 = IOTools.readDouble( "Anfangswert x0 = "); System.out.println( " " + x0); double eps = 1e-15; // Genauigkeit int max = 1000; // Maximalzahl der Iterationen // Newtoniteration Iteration it = new Iteration(); double erg = it.newton( polynom, x0, eps, max); System.out.println ( " Newton (" + it.getAnzahl() + "): " + erg); // Weiter weiter = IOTools.readChar ( "Neuer Anfangswert (j/n)? "); } while( weiter == 'j'); weiter = IOTools.readChar( "Neues Polynom (j/n)? "); } while( weiter == 'j'); // Abschluss System.out.println(); System.out.println( "Programm beendet"); } } /* ------------------------------------------------- */ // Testbeispiel /* Betrachte -3.0 + 7.0 x^1 + -5.0 x^2 + 1.0 x^3 = (x-3)(1.0 + -2.0 x^1 + 1.0 x^2)= (x-3)(x-1)(x-1) Polynomnullstellen Polynom -3.0 + 7.0 x^1 + -5.0 x^2 + 1.0 x^3 Anfangswert x0 = 4 Newton (6): 3.0 Math: 3.0 Polynom 1.0 + -2.0 x^1 + 1.0 x^2 Anfangswert x0 = 2 Newton (25): 1.0000000298023224 Math: 1.0 */