Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //МНГС
- #include <iostream>
- using namespace std;
- double function(double x[]){
- return x[0]*x[0]+x[0]*x[1]+x[1]*x[1]-2*x[0]+x[1];
- }
- int main() {
- double u;
- double a[2][2];
- double b[2], x1[2], e1[2],q1[2],aq[2], pr1[2], pr[2], xtest[2];
- double t[2];
- double x2=100000, min=100000, shag;
- double ort[1]={0};
- //init
- a[0][0]=2;a[0][1]=1;a[1][0]=1;a[1][1]=2;
- b[0]=-2;b[1]=1;
- x1[0]=0;x1[1]=0;
- e1[0]=1;e1[1]=0;
- int br;
- while(abs(function(x1)-x2)>1e-6){
- min = 100000;
- for (int p=0;p<2;p++){
- for (int i=0;i<=1;i++){
- xtest[i]=x1[i];
- if (i==p){
- ort[i]=1;
- }
- else ort[i]=0;
- }
- x2 = function(x1);
- for (int i=0;i<=1;i++){
- double s = b[i];
- for(int j=0;j<=1;j++){
- s+=a[i][j]*xtest[j];
- }
- q1[i]=s;
- }
- //A*ort
- for (int i=0;i<=1;i++){
- double s;
- s=0;
- for(int j=0;j<=1;j++){
- s+=a[i][j]*ort[j];
- }
- aq[i]=s;
- }
- double u;
- u = -q1[p]/aq[p];
- xtest[p]+=u;
- if (function(xtest)<min) {
- min = function(xtest);
- br = p;
- shag = u;
- }
- }
- x1[br] = x1[br] + shag;
- }
- cout<<"Point x: "<<endl;
- for (int i=0;i<2;i++){
- cout<<x1[i]<<" ";
- }
- cout<<endl;
- cout<<"f(x): "<<endl<<function(x1)<<endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement