Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <time.h>
  4. #include <iomanip>
  5. #include <math.h>
  6. using namespace std;
  7.  
  8. double func_sin(double x) {
  9.     return (0.1*cos(0.1*x)+0.05*sin(0.1*x));
  10. }
  11. void main() {
  12.     srand(time(NULL));
  13.     double etalon[45];
  14.     double Em,alpha,w1,w2,w3,y,T,t[45];
  15.     int Iter=1;
  16.     w1=(rand()%1000000)/1000000.0;
  17.     w2=(rand()%1000000)/1000000.0;
  18.     w3=(rand()%1000000)/1000000.0;
  19.     T=(rand()%1000000)/1000000.0;
  20.     cout << "Em="; cin >> Em;
  21.     cout << "alpha="; cin >> alpha;
  22.     double E,Er;
  23.     for(int i=1;i<=45;i++)
  24.         etalon[i-1]=func_sin(i/10.0);
  25.     double e=2.71,st;
  26.     double y1;
  27.     while(1) {
  28.         E=0;
  29.     for(int j=0;(j+3)<30;j++)
  30.     {
  31.          y=w1*etalon[j]+w2*etalon[j+1]+w3*etalon[j+2]-T;
  32.          st=pow(e,-y);
  33.          y1=1.0/(1.0+st);
  34.          w1=w1-alpha*(y1-etalon[j+3])*y1*(1-y1)*etalon[j];
  35.         w2=w2-alpha*(y1-etalon[j+3])*y1*(1-y1)*etalon[j+1];
  36.          w3=w3-alpha*(y1-etalon[j+3])*y1*(1-y1)*etalon[j+2];
  37.          T=T+alpha*(y1-etalon[j+3])*y1*(1-y1);
  38.     }
  39.     for(int j=0;(j+3)<30;j++)
  40.     {
  41.         y=w1*etalon[j]+w2*etalon[j+1]+w3*etalon[j+2]-T;
  42.          st=pow(e,-y);
  43.          y1=1.0/(1.0+st);
  44.          E=E+(y1-etalon[j+3])*(y1-etalon[j+3]);
  45.     }
  46.     E=E*0.5;
  47.     if(E<Em) { cout << "Gj!" << endl; break; }
  48.     Iter++;
  49.     if(Iter>10000000) { cout << "Huston we have problems! Restart this program!" << endl;
  50.                         system("pause"); return; }
  51.     }
  52.     cout << "Koff:" << endl;
  53.     cout << "w1=" << w1 << endl;
  54.     cout << "w2=" << w2 << endl;
  55.     cout << "w3=" << w3 << endl;
  56.     cout << "T=" << T << endl;
  57.     cout << "Speed(Steps) - "<< Iter << endl;
  58.     cout << "E=" << E << endl;
  59.     for(int i=0;i<42;i++)
  60.     {
  61.           if(i==27) cout <<  "--------------------------------------------------------------" << endl;
  62.              y=w1*etalon[i]+w2*etalon[i+1]+w3*etalon[i+2]-T;
  63.              y1=1.0/(1+pow(e,-y));
  64.          cout << i+4 << "." << setw(10) << etalon[i+3] << setw(12) << y1 << setw(15) << fabs(y1-etalon[i+3]) << endl;
  65.         // if(i>=27) etalon[i+2]=y;
  66.     }
  67.     system("pause");
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement