Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. /* Bisektionsverfahren 2.0 */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. double funktion (double x)            // hier wird das Polynom als Funktion definiert
  7. {
  8.         double erg = x*x*x*x*x+x+1;  // f(x) = x^5 + x + 1
  9.         return erg;
  10. }
  11.  
  12. int main (void)
  13. {
  14.         double a;                          // Beginn
  15.         printf("\nGeben Sie einen Wert fuer a ein:\n");
  16.         scanf("%lf",&a);
  17.         double b;                          // Ende
  18.         printf("\nGeben Sie einen Wert fuer b ein:\n");
  19.         scanf("%lf",&b);
  20.         double x = (a + b) / 2;         // Zwischenergebnisse und auch das Endergebnis
  21.         double e;                       // die Genauigkeit Epsilon
  22.         printf("\nGeben Sie einen Wert fuer e (z.B.:10e-6) ein:\n");
  23.         scanf("%lf",&e);
  24.         int summe = 0;
  25.         int k = 1;
  26.        
  27.         while( (b - a) > e )
  28.         {
  29.                 if(funktion(x) * funktion(b) < 0)
  30.                 {
  31.                         a = x;
  32.                 }
  33.                 else
  34.                 {
  35.                         b = x;
  36.                 }
  37.                 x = (a + b) / 2;
  38.                 summe = summe + k;
  39.         }
  40.          
  41.         printf("a: %lf\nb: %lf\nMittelwert: %lf\n", a, b, x); // Ausgabe des Ergebnisses
  42.         printf("\nAnzahl der durchlaufenen While-Schleifen:%i\n\n",summe);
  43.         system("PAUSE");              // verhindert das Schliessen des Konsolen-Fensters
  44.         return 0;
  45. }
Add Comment
Please, Sign In to add comment