Advertisement
Guest User

Work2

a guest
Aug 29th, 2012
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <math.h>
  3.  
  4. double Func(double);
  5. double dFunc(double);
  6. double func(double,double);                  // ïðîòîòèïû
  7. double dfunc(double,double);
  8. double getMaxFunc(double,double,double);
  9. double getQ(double,double,double,double);
  10.  
  11.  
  12.  
  13. double Func(double x)
  14. {
  15.      return exp(1.5-4*cos(2*x))-25*x;
  16. }
  17.      
  18. double dFunc(double x)
  19. {
  20.      return 8*sin(2*x)*exp(1.5-4*cos(2*x))-25;
  21. }
  22.      
  23. double func(double x, double mu)
  24. {
  25.      return x-mu*Func(x);
  26. }
  27.    
  28. double dfunc(double x, double mu)
  29. {
  30.      return 1-mu*dFunc(x);
  31. }
  32.      
  33. double getMaxFunc(double a, double b, double eps)
  34. {
  35.      double max = a;
  36.      double count = a; // count - ñ÷åò÷èê
  37.      do
  38.      {
  39.          count = count + eps;
  40.          if(dFunc(max)<dFunc(count))
  41.              max = count;
  42.      } while(count<=b);
  43.      return max;
  44. }
  45.  
  46. double getQ(double a, double b, double mu, double eps)
  47. {
  48.      double max = a;
  49.      double count = a;
  50.      do
  51.      {
  52.          count = count + eps;
  53.          if(dfunc(max,mu)<dfunc(count,mu))
  54.              max = count;
  55.      } while(count<=b);
  56.      return max;
  57. }
  58.  
  59. int main()
  60. {
  61.      double a,b,eps;
  62.      cout<<"Vvedite a,b,epsilon"<<endl;
  63.      cin>>a>>b>>eps;
  64.      for(int i=0; i<1; i++)
  65.      {
  66.          double mu = 1/getMaxFunc(a,b,eps);
  67.          double q = getQ(a,b,mu,eps);
  68.          double x,y = a;
  69.          
  70.          for(int i=0; i<10; i++)
  71.          {
  72.              x = y;
  73.              y = func(x,mu);
  74.              cout<<y<<endl;
  75.          }
  76.       }
  77.         return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement