Advertisement
rootUser

fixed point

Jun 12th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double f(double x)
  5. {
  6.     return x*x*x*x-3*x*x-3;  //change equation for each problem
  7. }
  8.  
  9. double g(double x)
  10. {
  11.     return pow(3*x*x+3,.25);
  12. }
  13.  
  14. int main()
  15. {
  16.     double p, p0, Tol;
  17.     int i=1;
  18.     int No;
  19.  
  20.     printf("Enter approximate p: ");
  21.     scanf ("%lf", &p0);
  22.  
  23.     printf("Desired Tolerance: ");
  24.     scanf ("%lf", &Tol);
  25.  
  26.     printf("Maximum Iterations: ");
  27.     scanf ("%d", &No);
  28.  
  29.  
  30.     while (i<=No)
  31.     {
  32.         p = g(p0);
  33.  
  34.         if((fabs(p-p0))<Tol)
  35.         {
  36.             //printf("%lf", &p);
  37.             break;
  38.         }
  39.         printf("Iteration %d: Current value = %lf\n", i, p);
  40.  
  41.         i++;  //i=i+1
  42.         p0=p;
  43.  
  44.         if (i>No)
  45.         {
  46.             printf("Method Failed after %d", No);
  47.             printf(" iterations");
  48.         }
  49.  
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement