Advertisement
Reemind

Untitled

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