Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <math.h>
  3. #include <locale.h>
  4. #include <stdio.h>
  5.  
  6. double funx(double phi, double r, double m, double h)
  7. {
  8.     return r*(m+1)*(cos(m*phi)-h*cos((m+1)*phi));
  9. }
  10.  
  11. double funy(double phi, double r, double m, double h)
  12. {
  13.     return r*(m+1)*(sin(m*phi)-h*sin((m+1)*phi));
  14. }
  15.  
  16. double Length(double Left,double Right,long N,double (*funx)(double, double, double, double), double (*funy)(double, double, double, double))
  17. {
  18.     double dphi,res=0.0,r=M_PI,m=1./3,h=0.15,phi;
  19.     dphi = (Right - Left) / N;
  20.     for (phi = Left; phi <= (Right-dphi); phi+=dphi)
  21.         res += sqrt(pow((funx(phi+dphi,r,m,h)-funx(phi,r,m,h)),2)+pow((funy(phi+dphi,r,m,h)-funy(phi,r,m,h)),2));
  22.     res += sqrt(pow((funx(Right,r,m,h)-funx(phi,r,m,h)),2)+pow((funy(Right,r,m,h)-funy(phi,r,m,h)),2));
  23.     return res;
  24. }
  25.  
  26. int main()
  27. {
  28.     long n;
  29.     double  L = 0.0, R = 6.0*M_PI;
  30.     double  V, V0=28.74656728; //28.74657809
  31.     setlocale( LC_ALL, "" );
  32.     printf("Число шагов;Относительная ошибка\n");
  33.     for (n = 1; n < 1000; n+=n/50+1) {
  34.         V = Length(L, R, n, funx, funy);
  35.         printf( "%ld;=%.15G\n", n, V-V0);
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement