Advertisement
kaspyx

Untitled

Mar 30th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define thshold 2 * pow(10,-4)
  5.  
  6. double sinfx(double x){
  7.  
  8.     return (x*x - sin(x));
  9. }
  10.  
  11. void false_position(double xl, double xu)
  12. {
  13.  
  14.     int i;
  15.    
  16.     double q0, q1, q,p;
  17.     double num = 40;  
  18.  
  19.     double xr2;
  20.  
  21.     q0 = sinfx(xl);
  22.     q1 = sinfx(xu);
  23.  
  24.     i = 1;
  25.  
  26.     p = xu - q1 * (xu - xl) / (q1 - q0);
  27.     q = sinfx(p);
  28.    
  29.     double e0=100.0;
  30.  
  31.     printf("%d\t%lf\t%lf\t%lf\t%lf\n", i, xl,xu,p, e0);
  32.  
  33.     while(1)
  34.     {
  35.  
  36.       p = xu - q1 * (xu - xl) / (q1 - q0);
  37.  
  38.       q = sinfx(p);
  39.  
  40.         if (e0 < thshold)
  41.         {
  42.            break;
  43.         }
  44.         else
  45.         {
  46.        
  47.             if((q*q1) < 0.)
  48.             {
  49.                 xl = xu; q0 = q1;
  50.             }
  51.  
  52.             xu = p; q1 = q;
  53.         }
  54.  
  55.         xr2 = (xl+xu)/2;
  56.  
  57.         e0 = fabs(q);
  58.        
  59.        
  60.         printf("%d\t%lf\t%lf\t%f\t   %lf\n", ++i, xu,xl,p,e0);
  61.  
  62.  
  63.        
  64.  
  65.     }
  66.  
  67.     printf("%lf\n", p);
  68.  
  69. }
  70.  
  71. int main()
  72. {
  73.     false_position(0.5,1);
  74.  
  75.     return 1;
  76. }
  77.  
  78.  
  79.  
  80. int pcap_compile    (   pcap_t *    p,
  81. struct bpf_program *    fp,
  82. char *  str,
  83. int     optimize,
  84. bpf_u_int32     netmask  
  85. )
  86.  
  87. int pcap_setfilter  (   pcap_t *    p,
  88. struct bpf_program *    fp   
  89. )  
  90.  
  91. int pcap_next_ex    (   pcap_t *    p,
  92. struct pcap_pkthdr **   pkt_header,
  93. const u_char **     pkt_data     
  94. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement