le)); (j=0; j lt ; nv; j ++) {[j]=x [j];
} [i] +=h;=(f (y) - f (x))/h; (y); df;
} LeftDS (double * x, double h, int i) {j; * y; df;=(double *) malloc (nv * sizeof (double)); (j=0; j lt ; nv; j ++) {[j]=x [j];
} [i] -=h;=(f (x) - f (y))/h; (y); df;
} * gradient (double * x, double h, int ds) {i; (ds gt; 2 || ds lt; 0) ds=0; * g;=(double *) malloc (nv * sizeof (double)); (i=0; i lt; nv; i ++) {[i]=DS [ds] (x, h, i);
} g;
} NormaV (double * x, int n) {i; Sk=0; (i=0; i lt; n; i ++) {+=x [i] * x [i];
} sqrt (Sk);
} argminf (double * x, double * p, double eps) {
double alfa; * ab=minimi (x, p, 0.01);//0.01 - оптимальний крок (підібраний експериментально)
alfa=zoloto (x, p, ab [0], ab [1], eps); (ab); alfa;
} * minimi (double * x, double * p, double dx) {i; m=0, a, b, k=1, alfa=0; * xda=(double *) malloc (nv * sizeof (double)); * xdb=(double *) malloc (nv * sizeof (double)); (i=0; i lt; nv; i ++) {[i]=x [i] + alfa * p [i]; [i]=x [i] + (alfa + dx) * p [i];
} (f (xda) lt; f (xdb)) m=- 1; m=1; *=m;=alfa + dx;=alfa + 3 * dx; j=1; {(i=0; i lt; nv; i ++) {[i]=x [i] + b * p [i]; [i]=x [i] + a * p [i];
} *=2; +=k * dx;=b - 2 * k * dx; ++;
} while (f (xda) gt; f (xdb)); ( [% 2d/, j); (xda); (xdb); -=k * dx; =b - 2 * k * dx; * s;=(double *) malloc (2 * sizeof (double)); (m == 1) {s [0]=a; s [1]=b;} {s [0]=b; s [1]=a;} s;
} zoloto (double * x, double * p, double a, double b, double eps) {i; x1, x2, tau, A, B; * xd1=(double *) malloc ( nv * sizeof (double)); * xd2=(double *) malloc (nv * sizeof (double));=(sqrt (5.) + 1.)/2.;=a + (ba)/(tau * tau );=a + (ba)/tau; (i=0; i lt; nv; i ++) {[i]=x [i] + x1 * p [i]; [i]=x [i] + x2 * p [i];
}=f (xd2);=f (xd1); j=0; {(A lt;=B) {= x2;=x1;=a + b - x2;=A; (i=0; i lt; nv; i ++) {[i]=x [i] + x1 * p [i];
}=f (xd1);
} {= x1;=x2;=a + b - x1;=B; (i=0; i lt; nv; i ++) {[i]=x [i] + x2 * p [i];
}=f (xd2);
} ++;
} while (fabs (ba) gt; eps); (% 2d] t , j); (xd1); (xd2); (b + a)/2 .;
} * ToRus (const char text []) {* buf=(char *) malloc (strlen (text) +1); (text, buf); buf;
}