#include "misc.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define M 9
#define a 0.
#define b x[0]
#define alpha x[1]

double R[M];

void fcn(int *n, double x[*n], double *f)
{
    int j;
    assert(*n == 2);
    *f = 0.0;
    for(j=0; j<M; j++)
	*f += SQR(R[j] - (a + b * pow(alpha, (double)j)));
}

int main(void)
{
    extern uncmnd_();
    const int N = 2, LW = N*(N+10);
    double x0[N], x[N], f, w[LW];
    int i;

R[0]=0.235655;
R[1]=0.784055;
R[2]=1.33367;
R[3]=3.83212;
R[4]=7.97882;
R[5]=10.7706;
R[6]=17.4592;
R[7]=37.0537;
R[8]=44.8196;

    x0[0]=1.;
    x0[1]=1.8;

    uncmnd_(&N, x0, fcn, x, &f, &i, w, &LW);

    printf("ierror = %d\n", i);
    printf("f(x*) = %g\n", f);
    printf("x* = ");
    for(i=0; i<N; i++)
	printf("%.16g ", x[i]);
    printf("\n");

    return 0;
}
