#include<iostream.h>
using namespace std; int main( ){
int in[3],d,w[3],a=0;
for(int i=0;i<3;i++) {
cout<<"\n initialize the weight vector w"<<i;
cin>>w[i];
}
for(int i=0;i<3;i++) {
cout<<"\n enter the input vector i"<<i;
cin>>in[i];
}
cout<<"\n enter the desired output";
cin>>d;
intans=1;
while(ans==1) {
for(int i=0;i<3;i++) {
a = a+w[i]* in[i];
}
cout<<"\n desired output is"<<d;
cout<<"\n actual output is "<<a;
int e;
e=d-a;
cout<<"\n error is"<<e;
cout<<"\n press 1 to adjust weight else 0";
cin>>ans;if (e<0){
for(int i=0;i<3;i++)
{
w [i]=w[i]-1;
} }
else if (e>0) {
for(int i=0;i<3;i++) {
w [i]=w[i]+1;
}
}
}
return 0;
}
OUTPUT:-initialize the weight vector w0 2initialize the weight vector w1 3initialize the weight vector w2 4
press 1 to adjust weight else 0
enter the input vector i0 enter the input vector i1 enter the input vector i2 enter the desired output4 | 56 | 7 |
desired output is actual output is 56 error is -52 | 4 |
0 Comments