Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <cmath>
- #define SIZE 7
- using std::cout;
- using std::cin;
- using std::endl;
- double x[] = { 0.0,0.8, 1, 2, 4, 6, 8};
- double y[] = { 0.0,2.1,2.15,2.2,2.3,2.4,2.5};
- 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<SIZE;i++)
- c+=y[i];
- cout<<"Поиск а из решения уравнения половинным делением "<<endl;
- do{
- a=(xbeg+xend)/2;
- 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<<"a = "<< a <<endl;
- cout<<"Проверка "<<endl;
- for(i=0;i<SIZE;i++)
- cout<<x[i]<<" "<<a*(1-exp(-x[i]/a))<<" "<<y[i]<<endl;
- }
- 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<SIZE;i++)
- s-=f1(x[i],a)*(x[i]+2*a-y[i]-y[i]*x[i]/a);
- for(i=0;i<SIZE;i++)
- s+=f2(x[i],a)*(x[i]+a);
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement