Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8736

FindMinimum v. NMinimize and an external program

From EcoTheory <carroll.ian@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject FindMinimum v. NMinimize and an external program
Date 2012-02-25 06:58 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jia0qc$1c4$1@smc.vnet.net> (permalink)

Show all headers | View raw


Can anyone say whether the following behavior is expected and why? I'd like to avoid learning how to use MathLink, but I need to use FindMinimum on a large external calculation and my way is broken.

Say there's a command line program called 'prog' that calculates y = (x-1)^2, reading x from a named pipe called 'in' and writing y to a named pipe called 'out'. Mathematica interacts with prog by reading and writing to the pipes. Like ...

> in = OpenWrite["in"];
> f[x_?NumericQ]:=(Write[in, CForm[x]]; First[ReadList["!cat out", Number]])

Calling NMinimize on f gives the correct answer, but FindMinimum doesn't. Specifically, FindMinimum[f[x], {x, 0}] returns the message FindMinimum::fmgz. That is, Mathematica thinks the gradient is zero.

I can't find a reason the two functions should behave differently. Any thoughts?

A couple details for the DIYers. Here's prog:
#include <stdio.h>
#include <math.h>
int main()
{
    FILE * io;
    int j;
    double x,y;

    while((j = scanf("%lf", &x)) != EOF)
    {
        y = pow((x-1.0), 2);
        io = fopen("out", "w");
        fprintf(io, "%e\n", y);
        fclose(io);
    }
    return;
}

Run prog with a redirect for stdin, as in
/prog < in

Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

FindMinimum v. NMinimize and an external program EcoTheory <carroll.ian@gmail.com> - 2012-02-25 06:58 +0000
  Re: FindMinimum v. NMinimize and an external program Szabolcs <szhorvat@gmail.com> - 2012-02-26 09:22 +0000
  Re: FindMinimum v. NMinimize and an external program Szabolcs <szhorvat@gmail.com> - 2012-02-26 09:21 +0000
    [solved] Re: FindMinimum v. NMinimize and an external program Ian <carroll.ian@gmail.com> - 2012-02-27 11:43 +0000

csiph-web