43 printf(
"%s('%s', %d, p[], %d, x[], y[], %d)\n", __func__, fid, parNr, sampleNr, verbose);
46 if(parNr<1 || p==NULL || sampleNr<1 || x==NULL || y==NULL)
return(1);
48 if(strcasecmp(fid,
"step")==0) {
50 if(parNr<2 || parNr&1)
return(2);
51 for(
int i=0; i<sampleNr; i++) {
53 for(
int j=0; j<parNr; j+=2)
if(x[i]>=p[j]) y[i]=p[j+1];
58 if(strcasecmp(fid,
"level")==0) {
59 for(
int i=0; i<sampleNr; i++) y[i]=p[0];
63 if(strcasecmp(fid,
"fengm2")==0) {
64 if(parNr<6)
return(2);
65 double delayt=0.0;
if(parNr>6) delayt=p[6];
66 for(
int i=0; i<sampleNr; i++) {
67 double xt=x[i]-delayt; y[i]=0.0;
if(!(xt>0.0))
continue;
68 y[i] += (p[0]*xt-p[2]-p[4])*exp(p[1]*xt);
69 y[i] += p[2]*exp(p[3]*xt);
70 y[i] += p[4]*exp(p[5]*xt);
74 if(strcasecmp(fid,
"fengm2s")==0) {
75 if(parNr<4)
return(2);
76 double delayt=0.0;
if(parNr>4) delayt=p[4];
77 for(
int i=0; i<sampleNr; i++) {
78 double xt=x[i]-delayt; y[i]=0.0;
if(!(xt>0.0))
continue;
79 y[i] += (p[0]*xt-p[2])*exp(p[1]*xt);
80 y[i] += p[2]*exp(p[3]*xt);
84 if(strcasecmp(fid,
"fengm2e")==0) {
85 if(parNr<8)
return(2);
86 double delayt=0.0;
if(parNr>8) delayt=p[8];
87 for(
int i=0; i<sampleNr; i++) {
88 double xt=x[i]-delayt; y[i]=0.0;
if(!(xt>0.0))
continue;
89 y[i] += (p[0]*xt-p[2]-p[4]-p[6])*exp(p[1]*xt);
90 y[i] += p[2]*exp(p[3]*xt);
91 y[i] += p[4]*exp(p[5]*xt);
92 y[i] += p[6]*exp(p[7]*xt);
97 if(strcasecmp(fid,
"gammav")==0) {
98 if(parNr<3)
return(2);
99 double delayt=0.0;
if(parNr>3) delayt=p[3];
100 for(
int i=0; i<sampleNr; i++) {
101 double xt=x[i]-delayt; y[i]=0.0;
102 if(!(xt>0.0) || fabs(p[2])<1.0E-10)
continue;
103 y[i] = p[0]*pow(xt, p[1])*exp(-xt/p[2]);
108 if(strcasecmp(fid,
"1exp")==0) {
109 if(parNr<2)
return(2);
110 for(
int i=0; i<sampleNr; i++) {
112 y[i] += p[0]*exp(p[1]*x[i]);
117 if(strcasecmp(fid,
"2exp")==0) {
118 if(parNr<4)
return(2);
119 for(
int i=0; i<sampleNr; i++) {
121 y[i] += p[0]*exp(p[1]*x[i]);
122 y[i] += p[2]*exp(p[3]*x[i]);
127 if(strcasecmp(fid,
"3exp")==0) {
128 if(parNr<6)
return(2);
129 for(
int i=0; i<sampleNr; i++) {
131 y[i] += p[0]*exp(p[1]*x[i]);
132 y[i] += p[2]*exp(p[3]*x[i]);
133 y[i] += p[4]*exp(p[5]*x[i]);
138 if(strcasecmp(fid,
"4exp")==0) {
139 if(parNr<8)
return(2);
140 for(
int i=0; i<sampleNr; i++) {
142 y[i] += p[0]*exp(p[1]*x[i]);
143 y[i] += p[2]*exp(p[3]*x[i]);
144 y[i] += p[4]*exp(p[5]*x[i]);
145 y[i] += p[6]*exp(p[7]*x[i]);
150 if(strcasecmp(fid,
"5exp")==0) {
151 if(parNr<10)
return(2);
152 for(
int i=0; i<sampleNr; i++) {
154 y[i] += p[0]*exp(p[1]*x[i]);
155 y[i] += p[2]*exp(p[3]*x[i]);
156 y[i] += p[4]*exp(p[5]*x[i]);
157 y[i] += p[6]*exp(p[7]*x[i]);
158 y[i] += p[8]*exp(p[9]*x[i]);
164 if(strcasecmp(fid,
"ppfigamc")==0) {
165 if(parNr<4)
return(2);
166 double delayt=0.0;
if(parNr>4) delayt=p[4];
169 double c=p[2];
if(c<0.0)
return(2);
170 double d=p[3];
if(d<=0.0)
return(2);
171 for(
int i=0; i<sampleNr; i++) {
172 double t=x[i]-delayt;
if(t<0.0) t=0.0;
173 y[i]=a*(1.0-b*
igam(d, c*t));
179 if(strcasecmp(fid,
"weibullcdfd")==0) {
180 if(parNr<4)
return(2);
182 for(
int i=0; i<sampleNr; i++) {
183 double xt=x[i]-delayt; y[i]=0.0;
184 if(!(xt>0.0))
continue;
185 y[i] = p[1]*(1.0-exp(-pow(xt/p[2], p[3])));
191 if(strcasecmp(fid,
"weibullcdfdd")==0) {
192 if(parNr<5)
return(2);
194 for(
int i=0; i<sampleNr; i++) {
195 double xt=x[i]-delayt; y[i]=0.0;
196 if(!(xt>0.0))
continue;
197 double a=exp(-pow(xt/p[2], p[3]));
198 double b=(p[3]/p[2]) * pow(xt/p[2], p[3]-1.0) * a;
199 y[i] = p[1]*(b + p[4]*(1.0-a));
206 if(strcasecmp(fid,
"dmsurge")==0) {
207 if(parNr<3)
return(2);
209 for(
int i=0; i<sampleNr; i++) {
210 double xt=x[i]-delayt;
213 for(
int pi=2; pi<parNr; pi+=2) {
216 y[i] += a*xt*exp(-b*xt);
224 if(strcasecmp(fid,
"surge")==0) {
225 if(parNr<2)
return(2);
226 double f=p[0]*(p[1]*p[1]);
227 for(
int i=0; i<sampleNr; i++) {
228 double xt=x[i]; y[i]=0.0;
229 if(!(xt>0.0))
continue;
230 y[i] = f*xt*exp(-p[1]*xt);
236 if(strcasecmp(fid,
"tradsurge")==0) {
237 if(parNr<2)
return(2);
238 for(
int i=0; i<sampleNr; i++) {
239 double xt=x[i]; y[i]=0.0;
240 if(!(xt>0.0))
continue;
241 y[i] = p[0]*xt*exp(-p[1]*xt);
248 if(strcasecmp(fid,
"surgerecirc")==0) {
249 if(parNr<2)
return(2);
252 for(
int i=0; i<sampleNr; i++) {
253 double xt=x[i]; y[i]=0.0;
254 if(!(xt>0.0))
continue;
255 double e=exp(-p[1]*xt);
256 y[i] = xt*e + (c/(p[1]*p[1]))*(1.0 - (p[1]*xt+1.0)*e);
264 if(strcasecmp(fid,
"surgerecircd")==0) {
265 if(parNr<2)
return(2);
266 double c=0.0;
if(parNr>=3) c=p[2];
267 double delayt=0.0;
if(parNr>=4) delayt=p[3];
268 for(
int i=0; i<sampleNr; i++) {
269 double xt=x[i]-delayt; y[i]=0.0;
270 if(!(xt>0.0))
continue;
271 double e=exp(-p[1]*xt);
272 y[i] = xt*e + (c/(p[1]*p[1]))*(1.0 - (p[1]*xt+1.0)*e);
281 if(strcasecmp(fid,
"p2bsrc")==0) {
282 if(parNr<3)
return(2);
283 double c=0.0;
if(parNr>=4) c=p[3];
287 for(
int i=0; i<sampleNr; i++) {
288 double xt=x[i];
if(!(xt>0.0)) {y[i]=1.0/(1.0-HCT);
continue;}
290 double r=a*(xt*e + (c/(b*b))*(1.0 - (b*xt+1.0)*e));
291 y[i] = 1.0/(1.0-HCT*(1.0-r));
298 if(strcasecmp(fid,
"p2bfm2")==0) {
299 if(parNr<3)
return(2);
303 double A2=0.0;
if(parNr>3) A2=p[3];
304 double L2=0.0;
if(parNr>4) L2=p[4];
305 double A3=0.0;
if(parNr>5) A3=p[5];
306 double L3=0.0;
if(parNr>6) L3=p[6];
307 for(
int i=0; i<sampleNr; i++) {
308 double xt=x[i];
if(!(xt>0.0)) {y[i]=1.0/(1.0-HCT);
continue;}
309 double r=(A1*xt - A2 - A3)*exp(-L1*xt) + A2*exp(-L2*xt) + A3*exp(-L3*xt);
310 y[i] = 1.0/(1.0-HCT*(1.0-r));
316 if(strcasecmp(fid,
"surgefdgaif")==0) {
317 if(parNr<5)
return(2);
319 for(
int i=0; i<sampleNr; i++) {
320 double xt=x[i]-delayt; y[i]=0.0;
321 if(!(xt>0.0))
continue;
322 y[i] = p[2]*(p[3]*xt*exp(-p[4]*p[1]*xt) + exp(-p[1]*xt));
328 if(strcasecmp(fid,
"erlangpdf")==0) {
329 if(parNr<3)
return(2);
330 double A=p[0], k=p[1];
if(!(k>=0.0))
return(2);
331 int N=(int)round(p[2]);
if(!(N>0))
return(2);
333 for(
int i=0; i<sampleNr; i++) {
334 y[i]=0.0;
if(!(x[i]>=0.0))
continue;
335 y[i] = A*pow(k, N)*pow(x[i], N-1)*exp(-k*x[i])/f;
341 if(strcasecmp(fid,
"ratf11")==0) {
342 if(parNr<4)
return(2);
343 for(
int i=0; i<sampleNr; i++) {
344 double a=p[0]+p[2]*x[i];
345 double b=p[1]+p[3]*x[i];
350 if(strcasecmp(fid,
"ratf21")==0) {
351 if(parNr<5)
return(2);
352 for(
int i=0; i<sampleNr; i++) {
353 double a=p[0]+p[2]*x[i]+p[4]*x[i]*x[i];
354 double b=p[1]+p[3]*x[i];
359 if(strcasecmp(fid,
"ratf22")==0) {
360 if(parNr<6)
return(2);
361 for(
int i=0; i<sampleNr; i++) {
362 double sqrx=x[i]*x[i];
363 double a=p[0]+p[2]*x[i]+p[4]*sqrx;
364 double b=p[1]+p[3]*x[i]+p[5]*sqrx;
369 if(strcasecmp(fid,
"ratf32")==0) {
370 if(parNr<7)
return(2);
371 for(
int i=0; i<sampleNr; i++) {
372 double sqrx=x[i]*x[i];
373 double a=p[0]+p[2]*x[i]+p[4]*sqrx+p[6]*sqrx*x[i];
374 double b=p[1]+p[3]*x[i]+p[5]*sqrx;
379 if(strcasecmp(fid,
"ratf33")==0) {
380 if(parNr<8)
return(2);
381 for(
int i=0; i<sampleNr; i++) {
382 double sqrx=x[i]*x[i];
383 double cubx=sqrx*x[i];
384 double a=p[0]+p[2]*x[i]+p[4]*sqrx+p[6]*cubx;
385 double b=p[1]+p[3]*x[i]+p[5]*sqrx+p[7]*cubx;
390 if(strcasecmp(fid,
"p2brf")==0) {
391 if(parNr<7)
return(2);
392 for(
int i=0; i<sampleNr; i++) {
396 double sqrx=x[i]*x[i];
397 double cubx=sqrx*x[i];
398 double a=0.0+p[1]*x[i]+p[3]*sqrx+p[5]*cubx;
399 double b=1.0+p[2]*x[i]+p[4]*sqrx+p[6]*cubx;
400 y[i]=1.0/(1.0-p[0]*(1.0-(a/b)));
407 if(strcasecmp(fid,
"mpfhill")==0) {
408 if(parNr<3)
return(2);
409 for(
int i=0; i<sampleNr; i++) {
410 y[i]=p[0]*pow(x[i], p[1]) / (pow(x[i], p[1]) + p[2]);
414 if(strcasecmp(fid,
"p2bhill")==0) {
415 if(parNr<4)
return(2);
416 for(
int i=0; i<sampleNr; i++) {
417 double cpr=p[1]*pow(x[i], p[2]) / (pow(x[i], p[2]) + p[3]);
418 y[i]=1.0/(1.0-p[0]*(1.0-cpr));
424 if(verbose>1) printf(
"function '%s' not supported by %s()\n", fid, __func__);
453 printf(
"%s('%s', %d, p[], %d, x[], y[], %d)\n", __func__, fid, parNr, sampleNr, verbose);
456 if(parNr<1 || p==NULL || sampleNr<1 || x==NULL || v==NULL)
return(1);
458 if(strcasecmp(fid,
"fengm2")==0) {
459 if(parNr<6)
return(2);
460 double delayt=0.0;
if(parNr>6) delayt=p[6];
462 double A1, A2, A3, L1, L2, L3;
463 A1=p[0]; L1=p[1]; A2=p[2]; L2=p[3]; A3=p[4]; L3=p[5];
464 if(fabs(L1)<1.0E-20 || fabs(L2)<1.0E-20 || fabs(L3)<1.0E-20) {
465 if(verbose>1) printf(
"too small L parameter(s)\n");
468 for(
int i=0; i<sampleNr; i++) {
469 double xt=x[i]-delayt; v[i]=0.0;
if(!(xt>0.0))
continue;
472 v[i] += (A1+L1*(A2+A3))*(1.0-a)/(L1*L1);
473 v[i] += (A1/L1)*xt*a;
475 if(L2!=0.0) v[i]-=(A2/L2)*(1.0-exp(L2*xt));
else v[i]+=A2*xt;
476 if(L3!=0.0) v[i]-=(A3/L3)*(1.0-exp(L3*xt));
else v[i]+=A3*xt;
480 if(strcasecmp(fid,
"fengm2e")==0) {
481 if(parNr<8)
return(2);
482 double delayt=0.0;
if(parNr>8) delayt=p[8];
484 double A1, A2, A3, A4, L1, L2, L3, L4;
485 A1=p[0]; L1=p[1]; A2=p[2]; L2=p[3]; A3=p[4]; L3=p[5]; A4=p[6]; L4=p[7];
486 if(fabs(L1)<1.0E-20 || fabs(L2)<1.0E-20 || fabs(L3)<1.0E-20 || fabs(L4)<1.0E-20) {
487 if(verbose>1) printf(
"too small L parameter(s)\n");
490 for(
int i=0; i<sampleNr; i++) {
491 double xt=x[i]-delayt; v[i]=0.0;
if(!(xt>0.0))
continue;
494 v[i] += (A1+L1*(A2+A3+A4))*(1.0-a)/(L1*L1);
495 v[i] += (A1/L1)*xt*a;
497 if(L2!=0.0) v[i]-=(A2/L2)*(1.0-exp(L2*xt));
else v[i]+=A2*xt;
498 if(L3!=0.0) v[i]-=(A3/L3)*(1.0-exp(L3*xt));
else v[i]+=A3*xt;
499 if(L4!=0.0) v[i]-=(A4/L4)*(1.0-exp(L4*xt));
else v[i]+=A4*xt;
503 if(strcasecmp(fid,
"fengm2s")==0) {
504 if(parNr<4)
return(2);
505 double delayt=0.0;
if(parNr>4) delayt=p[4];
507 double A1, A2, L1, L2;
508 A1=p[0]; L1=p[1]; A2=p[2]; L2=p[3];
509 if(fabs(L1)<1.0E-20 || fabs(L2)<1.0E-20) {
510 if(verbose>1) printf(
"too small L parameter(s)\n");
513 for(
int i=0; i<sampleNr; i++) {
514 double xt=x[i]-delayt; v[i]=0.0;
if(!(xt>0.0))
continue;
517 v[i] += (A1+L1*A2)*(1.0-a)/(L1*L1);
518 v[i] += (A1/L1)*xt*a;
520 if(L2!=0.0) v[i]-=(A2/L2)*(1.0-exp(L2*xt));
else v[i]+=A2*xt;
525 if(strcasecmp(fid,
"gammav")==0 && parNr>=3 && fabs(p[1]-1.0)<1.0E-10) {
526 if(parNr<3)
return(2);
527 double delayt=0.0;
if(parNr>3) delayt=p[3];
528 for(
int i=0; i<sampleNr; i++) {
529 double xt=x[i]-delayt; v[i]=0.0;
530 if(!(xt>0.0) || fabs(p[2])<1.0E-10)
continue;
531 v[i] = p[0]*p[2]*(p[2] - (p[2]+xt)*exp(-xt/p[2]));
538 if(strcasecmp(fid,
"dmsurge")==0) {
539 if(parNr<3)
return(2);
540 for(
int i=0; i<sampleNr; i++) {
544 for(
int pi=2; pi<parNr; pi+=2) {
549 v[i] += a*(1.0-(b*xt+1.0)*exp(-b*xt))/(b*b);
559 if(strcasecmp(fid,
"surge")==0) {
560 if(parNr<2)
return(2);
561 for(
int i=0; i<sampleNr; i++) {
562 double xt=x[i]; v[i]=0.0;
563 if(!(xt>0.0))
continue;
564 v[i] = p[0]*(1.0 - (p[1]*xt + 1.0)*exp(-p[1]*xt));
570 if(strcasecmp(fid,
"tradsurge")==0) {
571 if(parNr<2)
return(2);
572 double f=p[0]/(p[1]*p[1]);
573 for(
int i=0; i<sampleNr; i++) {
574 double xt=x[i]; v[i]=0.0;
575 if(!(xt>0.0))
continue;
576 v[i] = f*(1.0 - (p[1]*xt + 1.0)*exp(-p[1]*xt));
582 if(strcasecmp(fid,
"surgefdgaif")==0) {
583 if(parNr<5)
return(2);
585 for(
int i=0; i<sampleNr; i++) {
586 double xt=x[i]-delayt; v[i]=0.0;
587 if(!(xt>0.0))
continue;
588 v[i] += p[3]*(1.0-(p[4]*p[1]*xt + 1.0)*exp(-p[4]*p[1]*xt))/(p[1]*p[1]*p[4]*p[4]);
589 v[i] += (1.0-exp(-p[1]*xt))/p[1];
596 if(strcasecmp(fid,
"erlangpdf")==0 && p[2]<20.5) {
597 if(parNr<3)
return(2);
598 double A=p[0], k=p[1];
if(!(k>=0.0))
return(2);
599 int N=(int)round(p[2]);
if(!(N>=0) || N>20)
return(2);
601 for(
int i=0; i<sampleNr; i++) {
602 if(x[i]>=0.0) v[i]=A;
else v[i]=0.0;
605 for(
int i=0; i<sampleNr; i++) {
606 if(x[i]>=0.0) v[i]=A*(1.0-exp(-k*x[i]));
else v[i]=0.0;
609 for(
int i=0; i<sampleNr; i++) {
610 if(x[i]>=0.0) v[i]=A*(1.0 - exp(-k*x[i]) - k*x[i]*exp(-k*x[i]));
else v[i]=0.0;
613 for(
int i=0; i<sampleNr; i++) {
614 if(!(x[i]>=0.0)) {v[i]=0.0;
continue;}
616 for(
int j=2; j<N; j++) s+=pow(k*x[i], j)/
lfactorial(j);
617 v[i]=A*(1.0-s*exp(-k*x[i]));
625 if(strcasecmp(fid,
"1exp")==0) {
626 if(parNr<2)
return(2);
627 double A=p[0], k=p[1];
628 if(fabs(k)<1.0E-20) {
629 for(
int i=0; i<sampleNr; i++) v[i]=A*x[i];
631 for(
int i=0; i<sampleNr; i++) v[i]=(A/k)*(exp(k*x[i]) - 1.0);
635 if(strcasecmp(fid,
"2exp")==0) {
636 if(parNr<4)
return(2);
637 for(
int i=0; i<sampleNr; i++) v[i]=0.0;
638 for(
int n=0; n<=1; n++) {
639 double A=p[n*2], k=p[n*2+1];
640 if(fabs(k)<1.0E-20) {
641 for(
int i=0; i<sampleNr; i++) v[i]+=A*x[i];
643 for(
int i=0; i<sampleNr; i++) v[i]+=(A/k)*(exp(k*x[i]) - 1.0);
648 if(strcasecmp(fid,
"3exp")==0) {
649 if(parNr<6)
return(2);
650 for(
int i=0; i<sampleNr; i++) v[i]=0.0;
651 for(
int n=0; n<=2; n++) {
652 double A=p[n*2], k=p[n*2+1];
653 if(fabs(k)<1.0E-20) {
654 for(
int i=0; i<sampleNr; i++) v[i]+=A*x[i];
656 for(
int i=0; i<sampleNr; i++) v[i]+=(A/k)*(exp(k*x[i]) - 1.0);
661 if(strcasecmp(fid,
"4exp")==0) {
662 if(parNr<8)
return(2);
663 for(
int i=0; i<sampleNr; i++) v[i]=0.0;
664 for(
int n=0; n<=3; n++) {
665 double A=p[n*2], k=p[n*2+1];
666 if(fabs(k)<1.0E-20) {
667 for(
int i=0; i<sampleNr; i++) v[i]+=A*x[i];
669 for(
int i=0; i<sampleNr; i++) v[i]+=(A/k)*(exp(k*x[i]) - 1.0);
674 if(strcasecmp(fid,
"5exp")==0) {
675 if(parNr<10)
return(2);
676 for(
int i=0; i<sampleNr; i++) v[i]=0.0;
677 for(
int n=0; n<=4; n++) {
678 double A=p[n*2], k=p[n*2+1];
679 if(fabs(k)<1.0E-20) {
680 for(
int i=0; i<sampleNr; i++) v[i]+=A*x[i];
682 for(
int i=0; i<sampleNr; i++) v[i]+=(A/k)*(exp(k*x[i]) - 1.0);
688 if(verbose>1) printf(
"function '%s' not supported by %s()\n", fid, __func__);
717 printf(
"%s('%s', %d, p[], %d, x[], y[], %d)\n", __func__, fid, parNr, sampleNr, verbose);
720 if(parNr<1 || p==NULL || sampleNr<1 || x==NULL || v==NULL)
return(1);
723 double xt, delayt=0.0;
725 if(strcasecmp(fid,
"fengm2")==0) {
726 if(parNr<6)
return(2);
727 if(parNr>6) delayt=p[6];
728 double A1, A2, A3, L1, L2, L3;
729 A1=p[0]; L1=p[1]; A2=p[2]; L2=p[3]; A3=p[4]; L3=p[5];
730 if(fabs(L1)<1.0E-06 || fabs(L2)<1.0E-06 || fabs(L3)<1.0E-06) {
731 if(verbose>1) printf(
"too small L parameter(s)\n");
734 for(i=0; i<sampleNr; i++) {
735 xt=x[i]-delayt; v[i]=0.0;
if(!(xt>0.0))
continue;
737 v[i] += (((A1*xt-A2-A3)*L1 - 2.0*A1) * exp(L1*xt) + 2.0*A1)/(L1*L1*L1);
738 v[i] += (A1*xt+A2+A3)/(L1*L1);
739 v[i] += (A2*xt+A3*xt)/L1;
741 if(L2!=0.0) v[i] -= (A2/(L2*L2))*(1.0 - exp(L2*xt)) + A2*xt/L2;
742 if(L3!=0.0) v[i] -= (A3/(L3*L3))*(1.0 - exp(L3*xt)) + A3*xt/L3;
746 if(strcasecmp(fid,
"fengm2e")==0) {
747 if(parNr<8)
return(2);
748 if(parNr>8) delayt=p[8];
749 double A1, A2, A3, A4, L1, L2, L3, L4;
750 A1=p[0]; L1=p[1]; A2=p[2]; L2=p[3]; A3=p[4]; L3=p[5]; A4=p[6]; L4=p[7];
751 if(fabs(L1)<1.0E-15 || fabs(L2)<1.0E-15 || fabs(L3)<1.0E-15 || fabs(L4)<1.0E-15) {
752 if(verbose>1) printf(
"too small L parameter(s)\n");
755 for(i=0; i<sampleNr; i++) {
756 xt=x[i]-delayt; v[i]=0.0;
if(!(xt>0.0))
continue;
757 v[i] = A4*L1*L1*L1*L2*L2*L3*L3*L4*xt +
758 A4*L1*L1*L1*L2*L2*L3*L3*(1-exp(L4*xt)) +
759 L4*L4*(A3*L1*L1*L1*L2*L2*L3*xt + A3*L1*L1*L1*L2*L2*(1.0-exp(L3*xt)) +
760 L3*L3*(A2*L1*L1*L1*L2*xt + A2*L1*L1*L1*(1.0-exp(L2*xt)) -
761 L2*L2*((A2+A3+A4)*xt*L1*L1 + (A1*xt+A2+A3+A4)*L1 +
762 ((A1*xt-A2-A3-A4)*L1-2.0*A1)*exp(L1*xt) + 2.0*A1)));
763 v[i] /= -(L1*L1*L1*L2*L2*L3*L3*L4*L4);
768 if(strcasecmp(fid,
"gammav")==0 && parNr>=3 && fabs(p[1]-1.0)<1.0E-10) {
769 if(parNr<3)
return(2);
770 if(parNr>3) delayt=p[3];
771 for(i=0; i<sampleNr; i++) {
772 xt=x[i]-delayt; v[i]=0.0;
773 if(!(xt>0.0) || fabs(p[2])<1.0E-10)
continue;
774 v[i] = p[0]*p[2]*p[2]*((p[2]+p[2]+xt)*exp(-xt/p[2]) - p[2] - p[2] + xt);
779 if(verbose>1) printf(
"function '%s' not supported by %s()\n", fid, __func__);
809 printf(
"%s('%s', %d, p[], %d, x1[], x2[], y[], %d)\n", __func__, fid, parNr, sampleNr, verbose);
812 if(parNr<1 || p==NULL || sampleNr<1 || x1==NULL || x2==NULL || y==NULL)
return(1);
814 printf(
"p[] := %g", p[0]);
815 for(
int i=1; i<parNr; i++) printf(
", %g", p[i]);
820 double xt1, xt2, v, fd, delayt=0.0;
822 if(strcasecmp(fid,
"fengm2")==0) {
823 if(parNr<6)
return(2);
824 if(parNr>6) delayt=p[6];
825 double A1, A2, A3, L1, L2, L3;
826 A1=p[0]; L1=p[1]; A2=p[2]; L2=p[3]; A3=p[4]; L3=p[5];
827 if(fabs(L1)<1.0E-12 || fabs(L2)<1.0E-12 || fabs(L3)<1.0E-12) {
828 if(verbose>1) printf(
"too small L parameter(s)\n");
831 for(i=0; i<sampleNr; i++) {
832 xt1=x1[i]-delayt; xt2=x2[i]-delayt; y[i]=0.0;
833 if(xt1>xt2) {v=xt1; xt1=xt2; xt2=v;}
834 if(!(xt2>0.0))
continue;
838 ret=
mfEvalY(fid, parNr, p, 1, x2+i, y+i, verbose);
839 if(ret!=0)
return(ret);
842 if(!(xt1>0.0)) xt1=0.0;
844 y[i] = A3*L1*L1*L2*(exp(L3*xt1) - exp(L3*xt2)) +
845 L3*( A2*L1*L1*(exp(L2*xt1) - exp(L2*xt2)) +
846 L2*(((A1*xt1-A2-A3)*L1-A1)*exp(L1*xt1) -
847 ((A1*xt2-A2-A3)*L1-A1)*exp(L1*xt2)
850 y[i] /= -(L1*L1*L2*L3);
857 if(strcasecmp(fid,
"fengm2e")==0) {
858 if(parNr<8)
return(2);
859 if(parNr>8) delayt=p[8];
860 double A1, A2, A3, A4, L1, L2, L3, L4;
861 A1=p[0]; L1=p[1]; A2=p[2]; L2=p[3]; A3=p[4]; L3=p[5]; A4=p[6]; L4=p[7];
862 if(fabs(L1)<1.0E-20 || fabs(L2)<1.0E-20 || fabs(L3)<1.0E-20 || fabs(L4)<1.0E-20) {
863 if(verbose>1) printf(
"too small L parameter(s)\n");
866 for(i=0; i<sampleNr; i++) {
867 xt1=x1[i]-delayt; xt2=x2[i]-delayt; y[i]=0.0;
868 if(xt1>xt2) {v=xt1; xt1=xt2; xt2=v;}
869 if(!(xt2>0.0))
continue;
873 ret=
mfEvalY(fid, parNr, p, 1, x2+i, y+i, verbose);
874 if(ret!=0)
return(ret);
877 if(!(xt1>0.0)) xt1=0.0;
879 y[i] = A4*L1*L1*L2*L3*(exp(L4*xt1) - exp(L4*xt2)) +
880 L4*( A3*L1*L1*L2*(exp(L3*xt1) - exp(L3*xt2)) +
881 L3*( A2*L1*L1*(exp(L2*xt1) - exp(L2*xt2)) +
882 L2*(((A1*xt1-A2-A3-A4)*L1-A1)*exp(L1*xt1) -
883 ((A1*xt2-A2-A3-A4)*L1-A1)*exp(L1*xt2)
885 y[i] /= -(L1*L1*L2*L3*L4);
892 if(strcasecmp(fid,
"gammav")==0 && parNr>=3 && fabs(p[1]-1.0)<1.0E-10) {
893 if(parNr<3)
return(2);
894 if(parNr>3) delayt=p[3];
895 for(i=0; i<sampleNr; i++) {
896 xt1=x1[i]-delayt; xt2=x2[i]-delayt; y[i]=0.0;
897 if(fabs(p[2])<1.0E-10)
continue;
898 if(xt1>xt2) {v=xt1; xt1=xt2; xt2=v;}
899 if(!(xt2>0.0))
continue;
903 ret=
mfEvalY(fid, parNr, p, 1, x2+i, y+i, verbose);
904 if(ret!=0)
return(ret);
907 if(!(xt1>=0.0)) xt1=0.0;
909 y[i] = p[0]*p[2]*( (p[2]+xt1)*exp(-xt1/p[2]) - (p[2]+xt2)*exp(-xt2/p[2]) );
919 if(strcasecmp(fid,
"dmsurge")==0) {
920 if(parNr<3)
return(2);
922 for(
int i=0; i<sampleNr; i++) {
925 if(verbose>11) printf(
" fd[%d]=%g\n", i, fd);
926 if(!(fd>=0.0))
continue;
927 xt1=x1[i]-delayt; xt2=x2[i]-delayt;
928 if(!(xt2>0.0))
continue;
932 ret=
mfEvalY(fid, parNr, p, 1, x2+i, y+i, verbose);
933 if(ret!=0)
return(ret);
934 if(verbose>11) printf(
" y[%d]=%g\n", i, y[i]);
938 for(
int pi=2; pi<parNr; pi+=2) {
942 }
else if(fabs(b)<1.0E-10) {
943 y[i] += a*(xt2*xt2 - xt1*xt1);
945 y[i] += a*((b*xt1+1.0)*exp(-b*xt1) - (b*xt2+1.0)*exp(-b*xt2))/(b*b);
947 if(verbose>11) printf(
" a=%g b=%g xt1=%g xt2=%g y[%d]=%g\n", a, b, xt1, xt2, i, y[i]);
951 if(verbose>11) printf(
" y[%d]=%g\n", i, y[i]);
957 if(verbose>1) printf(
"function '%s' not supported by %s()\n", fid, __func__);