- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/peifer/diffit/modules/setInitialValues.cc File Reference

`#include <iostream>`
`#include <fstream>`
`#include "../def.h"`

Go to the source code of this file.

## Functions
void | setInitialValues (GlobExp *ex, int nP, double *parameters, double *yValues)

## Function Documentation

void setInitialValues | ( | GlobExp * | ex,
|  | int | nP,
|  | double * | parameters,
|  | double * | yValues
| ) |

| Definition at line 8 of file setInitialValues.cc. References GlobExp::mesh, GlobExp::nMeasure, GlobExp::nobs, GlobExp::nPoints, GlobExp::nvar, GlobExp::xMeasure, GlobExp::yMeasure, and GlobExp::yTry.
    00009 {
    00010   long i,j,k;
    00011   double xi, d, w1, w2;
    00012   long nobs=ex->nobs, nvar=ex->nvar, nMeasure=ex->nMeasure;
    00013   long nPoints=ex->nPoints;
    00014
    00015   /* set initial values */
    00016   if (yValues)
    00017     {
    00018       for (j=1; j<=nvar; ++j)
    00019         ex->yTry[1][j]=yValues[j];
    00020       i=2;
    00021     }
    00022   else
    00023     i=1;
    00024   k=1;
    00025
    00026   while (i<=nPoints)
    00027     {
    00028       xi=ex->mesh[i];
    00029       // make educated guess for yTry(xi)
    00030
    00031       // could be improved (polynomial interpolation/extrapolation etc.)
    00032
    00033       if (ex->xMeasure[k]>=xi)
    00034         {
    00035           // before first measurement: take first measured value
    00036           for (j=1; j<=nvar; ++j)
    00037             if (j<=nobs)
    00038               ex->yTry[i][j]=ex->yMeasure[k][j];
    00039             else
    00040               ex->yTry[i][j]=1;
    00041         } else if (k==nMeasure)
    00042           {
    00043             // after last measurement: take last measured value
    00044             for (j=1; j<=nvar; ++j)
    00045               if (j<=nobs)
    00046                 ex->yTry[i][j]=ex->yMeasure[k][j];
    00047               else
    00048                 ex->yTry[i][j]=1;
    00049           }
    00050       else
    00051         {
    00052           // interpolate linearly
    00053           while (k<nMeasure && ex->xMeasure[k]<xi)
    00054             ++k;
    00055           d=ex->xMeasure[k]-ex->xMeasure[k-1];
    00056           w1=(ex->xMeasure[k]-xi)/d;
    00057           w2=(xi-ex->xMeasure[k-1])/d;
    00058           for (j=1; j<=nvar; ++j)
    00059             if (j<=nobs)
    00060               ex->yTry[i][j]=w1*ex->yMeasure[k-1][j] + w2*ex->yMeasure[k][j];
    00061             else
    00062               ex->yTry[i][j]=1;
    00063         }
    00064       ++i;
    00065     }
    00066 }