Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <cmath>
- using std::cout;
- using std::cin;
- using std::endl;
- double x[] = { 0, 1.02, 2, 3, 4, 5, 6, 7, 8, 11};
- double y[] = { 0, 0.7, 0.74, 0.77, 0.8, 0.83, 0.86, 0.88, 0.91, 0.99};
- double a,xbeg,xend,c,f;
- int i;
- int main()
- {
- double f1(double x,double a);
- double f2(double x,double a);
- double fun(double a);
- setlocale(0, "");
- xbeg=0.1;xend=2;
- c=0;
- for(i=0;i<10;i++)
- c+=y[i];
- cout<<"Поиск а из решения уравнения половинным делением "<<endl;
- do{
- a=0.5*(xbeg+xend);
- f=fun(a);
- if(f*fun(xbeg)<0)
- xend=a;
- if(f*fun(xend)<0)
- xbeg=a;
- cout<<a<<" "<<fun(a)<<endl;
- }while(abs(f)>0.001);
- cout<<"Проверка "<<endl;
- for(i=0;i<10;i++)
- cout<<x[i]<<" "<<a*(1-exp(-x[i]/a))<<" "<<y[i]<<endl;
- system("pause"); // Только для тех, у кого MS Visual Studio
- }
- double f1(double x,double a)
- {
- return exp(-x/a);
- }
- double f2(double x,double a)
- {
- return exp(-2*x/a);
- }
- double fun(double a)
- {
- double s;
- s=0;
- s=s+10*a-c;
- for(i=0;i<10;i++)
- s-=f1(x[i],a)*(x[i]+2*a-y[i]-y[i]*x[i]/a);
- for(i=0;i<10;i++)
- s+=f2(x[i],a)*(x[i]+a);
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement