00001 #include<iostream>
00002 #include<fstream>
00003
00004 #include "../def.h"
00005
00006 using namespace std;
00007
00008 void setInitialValues(GlobExp *ex, int nP, double *parameters, double *yValues)
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
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
00030
00031
00032
00033 if (ex->xMeasure[k]>=xi)
00034 {
00035
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
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
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 }