Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include "optim.h"
- #define LEFT 0.0
- #define RIGHT 5.0
- #define EVALUATE 1e-10
- double f(double x) {
- numcount1++;
- return -(pow(sin(x), 6.0) * tan(1.0 - x) * exp(30.0 * x));
- }
- double f1(double x, double *d) {
- numcount1++;
- *d = exp(30.0 * x) * pow(sin(x), 5.0) * (sin(x) / pow(cos(1.0 - x), 2.0) - 6.0 * tan(1.0 - x) * (5.0 * sin(x) + cos(x)));
- return -(pow(sin(x), 6.0) * tan(1.0 - x) * exp(30.0 * x));
- }
- int main(int argc, char *argv[]) {
- double ax, bx, cx;
- double fa, fb, fc;
- double x;
- ax = LEFT; bx = RIGHT;
- numcount1 = 0;
- minbrack(f, &ax, &bx, &cx, &fa, &fb, &fc);
- x = golden(f, ax, bx, cx, 1e-10);
- printf("golden\tx = %e | max(f) = %e | funcs = %d | iters = %d\n", x, -f(x), numcount1, itercount1);
- numcount1 = 0;
- x = fmin1(f, LEFT, RIGHT, 0.0);
- printf("fmin\tx = %e | max(f) = %e | funcs = %d | iters = %d\n", x, -f(x), numcount1, itercount1);
- numcount1 = 0;
- x = davidon(f1, LEFT, RIGHT, EVALUATE, 1e-10);
- printf("davidon\tx = %e | max(f) = %e | funcs = %d | iters = %d\n", x, -f(x), numcount1, itercount1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment