Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <time.h>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- double func_sin(double x) {
- return (0.1*cos(0.1*x)+0.05*sin(0.1*x));
- }
- void main() {
- srand(time(NULL));
- double etalon[45];
- double Em,alpha,w1,w2,w3,y,T,t[45];
- int Iter=1;
- w1=(rand()%1000000)/1000000.0;
- w2=(rand()%1000000)/1000000.0;
- w3=(rand()%1000000)/1000000.0;
- T=(rand()%1000000)/1000000.0;
- cout << "Em="; cin >> Em;
- cout << "alpha="; cin >> alpha;
- double E,Er;
- for(int i=1;i<=45;i++)
- etalon[i-1]=func_sin(i/10.0);
- double e=2.71,st;
- double y1;
- while(1) {
- E=0;
- for(int j=0;(j+3)<30;j++)
- {
- y=w1*etalon[j]+w2*etalon[j+1]+w3*etalon[j+2]-T;
- st=pow(e,-y);
- y1=1.0/(1.0+st);
- w1=w1-alpha*(y1-etalon[j+3])*y1*(1-y1)*etalon[j];
- w2=w2-alpha*(y1-etalon[j+3])*y1*(1-y1)*etalon[j+1];
- w3=w3-alpha*(y1-etalon[j+3])*y1*(1-y1)*etalon[j+2];
- T=T+alpha*(y1-etalon[j+3])*y1*(1-y1);
- }
- for(int j=0;(j+3)<30;j++)
- {
- y=w1*etalon[j]+w2*etalon[j+1]+w3*etalon[j+2]-T;
- st=pow(e,-y);
- y1=1.0/(1.0+st);
- E=E+(y1-etalon[j+3])*(y1-etalon[j+3]);
- }
- E=E*0.5;
- if(E<Em) { cout << "Gj!" << endl; break; }
- Iter++;
- if(Iter>10000000) { cout << "Huston we have problems! Restart this program!" << endl;
- system("pause"); return; }
- }
- cout << "Koff:" << endl;
- cout << "w1=" << w1 << endl;
- cout << "w2=" << w2 << endl;
- cout << "w3=" << w3 << endl;
- cout << "T=" << T << endl;
- cout << "Speed(Steps) - "<< Iter << endl;
- cout << "E=" << E << endl;
- for(int i=0;i<42;i++)
- {
- if(i==27) cout << "--------------------------------------------------------------" << endl;
- y=w1*etalon[i]+w2*etalon[i+1]+w3*etalon[i+2]-T;
- y1=1.0/(1+pow(e,-y));
- cout << i+4 << "." << setw(10) << etalon[i+3] << setw(12) << y1 << setw(15) << fabs(y1-etalon[i+3]) << endl;
- // if(i>=27) etalon[i+2]=y;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement