Origin 8.5.1 win vista
Hi
I d like to fit a dataset with a piecewise function being quadratic up to threshold_1, cubic between threshold1 and threshold2 and again quadratic above threshold2
However the piecewise fitting function must be continuous as well as its first derivative
I tried ti define the function like this
//
void _nlsfTestFitPiecewise(
// Fit Parameter(s):
double a0, double a1, double a2, double b0, double b1, double b2, double b3, double c0,
double c1, double c2, double d0, double d1,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
if (x<d0)
y = a0+a1*x+a2*x^2;
else
if (x<d1)
y = b0+b1*x+b2*x^2+b3*x^3;
else
y=c0+c1*x+c2*x^2;
// End of editable part
}
This works fine but i don't know how to implement the continuity of the function and its derivative that is to say the following constraints
a0+a1*d0+a2*d0^2=b0+b1*d0+b2*d0^2+b3*d0^3;
a1+2*a2*d0=b1+2*b1*d0+3*b3*d0^2;
c0+c1*d1+c2*d1^2=b0+b1*d1+b2*d1^2+b3*d1^3;
c1+2*c2*d1=b1+2*b1*d1+3*b3*d1^2;