// RegulaFalsiIterationTest.java MM 2012 /** * Test der Ragula falsi Iteration. */ public class RegulaFalsiIterationTest { /** * Zwei Beispiele: * 2. Wurzel aus 4 * Polynom -3.0 + 7.0 x^1 + -5.0 x^2 + 1.0 x^3. */ public static void main( String[] args) { // Beispiel 1: Wurzelberechnung double[] koeff1 = new double[ 3]; koeff1[ 0] = -4; koeff1[ 1] = 0; koeff1[ 2] = 1; Polynom polynom1 = new Polynom(); polynom1.setPolynom( koeff1); System.out.println( "\n" + polynom1); // Nullstelleniteration nach Regula falsi double eps = 1e-15; // Genauigkeit int max = 100; // Maximale Anzahl der Iterationen Iteration it = new Iteration(); double erg1 = it.regulaFalsi( polynom1, 4, 1, eps, max); System.out.println ( " Regula (" + it.getAnzahl() + "): " + erg1); /* ------------------------------------------------- */ // Beispiel 2: Nullstellen eines Polynoms double[] koeff2 = new double[ 4]; koeff2[ 0] = -3; koeff2[ 1] = 7; koeff2[ 2] = -5; koeff2[ 3] = 1; Polynom polynom2 = new Polynom(); polynom2.setPolynom( koeff2); System.out.println( "\n" + polynom2); // Nullstelleniteration nach Regula falsi double erg2 = it.regulaFalsi( polynom2, 4, 2, eps, max); System.out.println ( " Regula (" + it.getAnzahl() + "): " + erg2); } } /* ------------------------------------------------- */ // Testbeispiele /* Beispiel 1, mthematische Loesung : 2.0 -4.0 + 0.0 x^1 + 1.0 x^2 x0: 4.0 x1: 1.0 x0: 1.5999999999999996 x1: 4.0 x0: 1.857142857142857 x1: 4.0 ... x0: 1.9999999999999936 x1: 4.0 x0: 1.9999999999999978 x1: 4.0 x0: 1.9999999999999993 x1: 4.0 Regula (33): 1.9999999999999998 Beispiel 2, mthematische Loesung : 3.0 -3.0 + 7.0 x^1 + -5.0 x^2 + 1.0 x^3 x0: 4.0 x1: 2.0 x0: 2.2 x1: 4.0 x0: 2.404255319148936 x1: 4.0 x0: 2.588498402555911 x1: 4.0 ... x0: 2.999999999999997 x1: 4.0 x0: 2.9999999999999982 x1: 4.0 x0: 2.999999999999999 x1: 4.0 Regula (62): 2.9999999999999996 */