Advertisement
Reemind

Untitled

Jul 23rd, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <cmath>
  5.  
  6. #define SIZE 7
  7.  
  8. using std::cout;
  9. using std::cin;
  10. using std::endl;
  11. double x[] = { 0.0,0.8, 1, 2, 4, 6, 8};
  12. double y[] = { 0.0,2.1,2.15,2.2,2.3,2.4,2.5};
  13. double a,xbeg,xend,c,f;
  14. int i;
  15.  
  16. int main()
  17. {
  18. double f1(double x,double a);
  19. double f2(double x,double a);
  20. double fun(double a);
  21.    setlocale(0, "");
  22.    xbeg=0.1;xend=2;
  23.    c=0;
  24.    for(i=0;i<SIZE;i++)
  25.        c+=y[i];
  26.    cout<<"Поиск а из решения уравнения половинным делением "<<endl;
  27.    do{  
  28.    a=(xbeg+xend)/2;
  29.    f=fun(a);
  30.    if(f*fun(xbeg)<0)
  31.        xend=a;
  32.    if(f*fun(xend)<0)
  33.        xbeg=a;
  34.     cout<<a<<"  "<<fun(a)<<endl;
  35.    }while(abs(f)>0.001);
  36.    
  37.    cout<<"a = "<< a <<endl;
  38.    cout<<"Проверка "<<endl;
  39.    for(i=0;i<SIZE;i++)
  40.    cout<<x[i]<<" "<<a*(1-exp(-x[i]/a))<<"  "<<y[i]<<endl;
  41. }
  42.  
  43. double f1(double x,double a)
  44. {
  45. return exp(-x/a);
  46. }
  47.  
  48. double f2(double x,double a)
  49. {
  50.     return exp(-2*x/a);
  51. }
  52.  
  53. double fun(double a)
  54. {
  55.     double s;
  56.     s=0;
  57.     s=s+10*a-c;
  58.  
  59.     for(i=0;i<SIZE;i++)
  60.         s-=f1(x[i],a)*(x[i]+2*a-y[i]-y[i]*x[i]/a);
  61.  
  62.     for(i=0;i<SIZE;i++)
  63.         s+=f2(x[i],a)*(x[i]+a);
  64.     return s;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement