Commit 43d380af authored by Vesa Oikonen's avatar Vesa Oikonen
Browse files

mfEvalInt() accepts exponential functions

parent 01d0acfc
......@@ -432,6 +432,69 @@ int mfEvalInt(
return(0);
}
/* Exponential functions */
if(strcasecmp(fid, "1exp")==0) {
if(parNr<2) return(2);
double A=p[0], k=p[1];
if(fabs(k)<1.0E-20) {
for(int i=0; i<sampleNr; i++) v[i]=A*x[i];
} else {
for(int i=0; i<sampleNr; i++) v[i]=(A/k)*(exp(k*x[i]) - 1.0);
}
return(0);
}
if(strcasecmp(fid, "2exp")==0) {
if(parNr<4) return(2);
for(int i=0; i<sampleNr; i++) v[i]=0.0;
for(int n=0; n<=1; n++) {
double A=p[n*2], k=p[n*2+1];
if(fabs(k)<1.0E-20) {
for(int i=0; i<sampleNr; i++) v[i]+=A*x[i];
} else {
for(int i=0; i<sampleNr; i++) v[i]+=(A/k)*(exp(k*x[i]) - 1.0);
}
}
return(0);
}
if(strcasecmp(fid, "3exp")==0) {
if(parNr<6) return(2);
for(int i=0; i<sampleNr; i++) v[i]=0.0;
for(int n=0; n<=2; n++) {
double A=p[n*2], k=p[n*2+1];
if(fabs(k)<1.0E-20) {
for(int i=0; i<sampleNr; i++) v[i]+=A*x[i];
} else {
for(int i=0; i<sampleNr; i++) v[i]+=(A/k)*(exp(k*x[i]) - 1.0);
}
}
return(0);
}
if(strcasecmp(fid, "4exp")==0) {
if(parNr<8) return(2);
for(int i=0; i<sampleNr; i++) v[i]=0.0;
for(int n=0; n<=3; n++) {
double A=p[n*2], k=p[n*2+1];
if(fabs(k)<1.0E-20) {
for(int i=0; i<sampleNr; i++) v[i]+=A*x[i];
} else {
for(int i=0; i<sampleNr; i++) v[i]+=(A/k)*(exp(k*x[i]) - 1.0);
}
}
return(0);
}
if(strcasecmp(fid, "5exp")==0) {
if(parNr<10) return(2);
for(int i=0; i<sampleNr; i++) v[i]=0.0;
for(int n=0; n<=4; n++) {
double A=p[n*2], k=p[n*2+1];
if(fabs(k)<1.0E-20) {
for(int i=0; i<sampleNr; i++) v[i]+=A*x[i];
} else {
for(int i=0; i<sampleNr; i++) v[i]+=(A/k)*(exp(k*x[i]) - 1.0);
}
}
return(0);
}
if(verbose>1) printf("function '%s' not supported by %s()\n", fid, __func__);
return(10);
......
......@@ -376,6 +376,73 @@ int test_mfEvalInt(
{
char *fid="1exp";
if(verbose>1) printf("\n testing '%s' \n", fid);
double p1[]={100., -0.8};
int i, n=3;
double x[]={0.0, 10., 100.};
double y[n];
double cy1[]={0.0, 124.9580672, 125.};
ret=mfEvalInt("1exp", 2, p1, n, x, y, verbose-2);
if(ret!=0) return(501);
for(i=0; i<n; i++) {
if(verbose>3) printf(" %g : %g vs %g \n", x[i], cy1[i], y[i]);
if(!doubleMatch(cy1[i], y[i], 1.0E-05)) return(502);
}
if(verbose>2) printf("\n ok \n");
}
{
char *fid="4exp";
if(verbose>1) printf("\n testing '%s' \n", fid);
double p1[]={100., -0.8, 50, -0.2, 20., -0.05, 2., -0.001};
int i, n=3;
double x[]={0.0, 10., 100.};
double y[n];
double cy1[]={0.0, 518.412315, 962.6299846};
ret=mfEvalInt("4exp", 8, p1, n, x, y, verbose-2);
if(ret!=0) return(511);
for(i=0; i<n; i++) {
if(verbose>3) printf(" %g : %g vs %g \n", x[i], cy1[i], y[i]);
if(!doubleMatch(cy1[i], y[i], 1.0E-05)) return(512);
}
if(verbose>2) printf("\n ok \n");
p1[6]=p1[7]=0.0;
cy1[1]=498.5119825;
cy1[2]=772.3048207;
ret=mfEvalInt("4exp", 8, p1, n, x, y, verbose-2);
if(ret!=0) return(513);
for(i=0; i<n; i++) {
if(verbose>3) printf(" %g : %g vs %g \n", x[i], cy1[i], y[i]);
if(!doubleMatch(cy1[i], y[i], 1.0E-05)) return(514);
}
if(verbose>2) printf("\n ok \n");
}
{
char *fid="5exp";
if(verbose>1) printf("\n testing '%s' \n", fid);
double p1[]={100., -0.8, 50, -0.2, 20., -0.05, 2., -0.01, 0.1, 0.0};
int i, n=3;
double x[]={0.0, 10., 100.};
double y[n];
double cy1[]={0.0, 518.5444989, 908.7289325};
ret=mfEvalInt("5exp", 10, p1, n, x, y, verbose-2);
if(ret!=0) return(521);
for(i=0; i<n; i++) {
if(verbose>3) printf(" %g : %g vs %g \n", x[i], cy1[i], y[i]);
if(!doubleMatch(cy1[i], y[i], 1.0E-05)) return(522);
}
if(verbose>2) printf("\n ok \n");
}
statusSet(status, __func__, __FILE__, __LINE__, 0);
return(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment