Application Center - Maplesoft

App Preview:

An Algorithm For Fitting Nonlinear Piecewise Functions, with an Application to Animal Growth

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

nonlinearpiecewise.mws

An Algorithm For Fitting Nonlinear Piecewise Functions

Stanislav Barton              barton@mendelu.cz

Dept. of Physics             ++ 420 5 520844 - privat & fax

Mendel Univ.                 ++ 420 5 4513 2127 - office

Zemedelska 1

613 00 Brno  Czech Rep.                                                                 

This worksheet shows how to find parameters of two nonlinear functions fitting the given points [X[i], Y[i]][i = 1 .. N] . The first function f1(a1,b1,c1,x)   is valid on the range x  = <0.. xi >, the second one   f2(a2,b2,c2,x)  on the range x  = < xi .. infinity ). Where a1,a2,b1,b2 are linear and  c1, c2  are nonlinear parameters. Both functions have to satisfy continuity conditions at the point xi , ie. f1(a1,a2,c1,xi) = f2(a2,b2,c2,xi)  and Diff(f1(a1,b1,c1,x),x)[x = xi] = Diff(f2(a2,b2,c2),x)[x = xi] . These conditions enable us to determine the two parameters b1  and b2  as a functions b1(a1,a2,c1,c2,xi)  and b2(a1,a2,c1,c2,xi) . The remaining linear parameters a1, a2, c1, c2 and point of the continuity xi  could be computed using the Least Squares Method minimizing the squared sum of the residuals S , ie. S(a1,a2,c1,c2,xi) = Sum((Y1[i]-f1(a1,a2,c1,c2,xi,X1[i]))^2,i = 1 .. N1)+Sum((Y2[i]-f2(a1,a2,c1,c2,xi,X2[i]))^2,i = 1 .. N2)  by solving its normal equations ie.: Ea1 := Diff(S(a1,a2,c1,c2,xi),a1) = 0 , Ea2 := Diff(S(a1,a2,c1,c2,xi),a2) = 0 , Ec1 := Diff(S(a1,a2,c1,c2,xi),c1) = 0 , Ec2 := Diff(S(a1,a2,c1,c2,xi),c2) = 0  and Exi := Diff(S(a1,a2,c1,c2,xi),xi) = 0 . The point xi  splits data vectors X and Y into two subvectors X1 and corresponding Y1 for X[i] <= xi , X2 and corresponding Y2 for xi < X[i] . The equations Ea1  and Ea2  are linear in a1  and a2 , so we can solve them: a1 = a1(c1,c2,xi)  and a2 = a2(c1,c2,xi) . The remaining equations Ec1, Ec2  and Exi  are nonlinear for c1 , c2  and xi , so we shall solve them using Newton's method. To save space we shall use the following notation: Sc1 := Sc1(a1(c1,c2,xi),a2(c1,c2,xi),c1,c2,xi)  for the equation Sc1  and very simillar for Sc2 and Sxi . Newton's method is based on the linerization of functions, se we have to build the set of 3 equations:  

EQ1 := Sc1+Diff(Sc1,c1)*dc1+Diff(Sc1,c2)*dc2+Diff(Sc1,xi)*dxi = 0  

EQ2 := Sc2+Diff(Sc2,c1)*dc1+Diff(Sc2,c2)*dc2+Diff(Sc2,xi)*dxi = 0

EQ3 := Sxi+Diff(Sxi,c1)*dc1+Diff(Sxi,c2)*dc2+Diff(Sxi,xi)*dxi = 0 .

If we assign proper initial numerical values c1 := c1i , c2 := c2i   and xi := xii , we can solve these equations for   the corrections  dc1 , dc2  and dxii  and to build new initial values c1i := c1i+dc1 , c2i := c2i+dc2  and xii := xii+dxi  and we can compute again new corrections. The procedure terminates when these corrections become smaller than the desired precision.

>    restart; with(linalg): with(plots): Maple start

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the name changecoords has been redefined

>    g:=45+650*exp(-exp(-t/250)*6);  Widely used Gompertz function - Pattern of the growth of a bull. We shall try to approximate it.

g := 45+650*exp(-6*exp(-1/250*t))

>    plot(g,t=0..1500,title=`Gompertz function`,labels=["t [days]","M [kg]"]);

[Maple Plot]

>    f1:=t->a1+b1*exp(t/c1);
f2:=t->a2-b2*exp(-t/c2);
Definition of new functions,   f1(t)  for   t = `<,>`(0,xi)  and f2(t)  for t = `<,>`(xi,infinity)

f1 := proc (t) options operator, arrow; a1+b1*exp(t/c1) end proc

f2 := proc (t) options operator, arrow; a2-b2*exp(-t/c2) end proc

>    e1:=f1(xi)=f2(xi);  
e2:=diff(f1(xi),xi)=diff(f2(xi),xi);
Continuity condition and continuity of the 1st derivatives

e1 := a1+b1*exp(xi/c1) = a2-b2*exp(-xi/c2)

e2 := b1/c1*exp(xi/c1) = b2/c2*exp(-xi/c2)

>    sol:=solve({e1,e2},{b1,b2}); Determination of two linear coefficients

sol := {b2 = -c2*(a1-a2)/exp(-xi/c2)/(c2+c1), b1 = -1/exp(xi/c1)*(a1-a2)/(c2+c1)*c1}

>    assign(sol);

>    s1:=expand(K*(M1[i]-f1(T1[i]))^2);
s2:=expand(K*(M2[i]-f2(T2[i]))^2);
 Squared residuals of the 1st and 2nd functions. K  is necessary to create products at each element of the result

s1 := K*M1[i]^2-2*K*M1[i]*a1+2*K/exp(xi/c1)/(c2+c1)*c1*exp(T1[i]/c1)*a1*M1[i]-2*K/exp(xi/c1)/(c2+c1)*c1*exp(T1[i]/c1)*a2*M1[i]+K*a1^2-2*K/exp(xi/c1)/(c2+c1)*c1*exp(T1[i]/c1)*a1^2+2*K/exp(xi/c1)/(c2+c1)...
s1 := K*M1[i]^2-2*K*M1[i]*a1+2*K/exp(xi/c1)/(c2+c1)*c1*exp(T1[i]/c1)*a1*M1[i]-2*K/exp(xi/c1)/(c2+c1)*c1*exp(T1[i]/c1)*a2*M1[i]+K*a1^2-2*K/exp(xi/c1)/(c2+c1)*c1*exp(T1[i]/c1)*a1^2+2*K/exp(xi/c1)/(c2+c1)...

s2 := K*M2[i]^2-2*K*M2[i]*a2-2*K*c2*exp(xi/c2)/(c2+c1)/exp(T2[i]/c2)*a1*M2[i]+2*K*c2*exp(xi/c2)/(c2+c1)/exp(T2[i]/c2)*a2*M2[i]+K*a2^2+2*K*c2*exp(xi/c2)/(c2+c1)/exp(T2[i]/c2)*a1*a2-2*K*c2*exp(xi/c2)/(c2...
s2 := K*M2[i]^2-2*K*M2[i]*a2-2*K*c2*exp(xi/c2)/(c2+c1)/exp(T2[i]/c2)*a1*M2[i]+2*K*c2*exp(xi/c2)/(c2+c1)/exp(T2[i]/c2)*a2*M2[i]+K*a2^2+2*K*c2*exp(xi/c2)/(c2+c1)/exp(T2[i]/c2)*a1*a2-2*K*c2*exp(xi/c2)/(c2...

>    s1:=map(u->remove(has,u,i)
          *simplify(sum(select(has,u,i),i=1..N1)),s1);
s2:=map(u->remove(has,u,i)
          *simplify(sum(select(has,u,i),i=1..N2)),s2);
 Residuals are summed.

s1 := K*sum(M1[i]^2,i = 1 .. N1)-2*K*a1*sum(M1[i],i = 1 .. N1)+2*K/exp(xi/c1)/(c2+c1)*c1*a1*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)-2*K/exp(xi/c1)/(c2+c1)*c1*a2*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)+K*a1^2...
s1 := K*sum(M1[i]^2,i = 1 .. N1)-2*K*a1*sum(M1[i],i = 1 .. N1)+2*K/exp(xi/c1)/(c2+c1)*c1*a1*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)-2*K/exp(xi/c1)/(c2+c1)*c1*a2*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)+K*a1^2...
s1 := K*sum(M1[i]^2,i = 1 .. N1)-2*K*a1*sum(M1[i],i = 1 .. N1)+2*K/exp(xi/c1)/(c2+c1)*c1*a1*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)-2*K/exp(xi/c1)/(c2+c1)*c1*a2*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)+K*a1^2...

s2 := K*sum(M2[i]^2,i = 1 .. N2)-2*K*a2*sum(M2[i],i = 1 .. N2)-2*K*c2*exp(xi/c2)/(c2+c1)*a1*sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2)+2*K*c2*exp(xi/c2)/(c2+c1)*a2*sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2)+K*a2...
s2 := K*sum(M2[i]^2,i = 1 .. N2)-2*K*a2*sum(M2[i],i = 1 .. N2)-2*K*c2*exp(xi/c2)/(c2+c1)*a1*sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2)+2*K*c2*exp(xi/c2)/(c2+c1)*a2*sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2)+K*a2...
s2 := K*sum(M2[i]^2,i = 1 .. N2)-2*K*a2*sum(M2[i],i = 1 .. N2)-2*K*c2*exp(xi/c2)/(c2+c1)*a1*sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2)+2*K*c2*exp(xi/c2)/(c2+c1)*a2*sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2)+K*a2...

>    K:=1:  K is no longer necessary

>    DE:=[diff(E1(c1,xi),c1,c1)=E1c1c1, diff(E1(c1,xi),xi,xi)=E1xixi,
     diff(E1(c1,xi),c1,xi)=E1c1xi, diff(E1(c1,xi),c1)=E1c1,
     diff(E1(c1,xi),xi)=E1xi, E1(c1,xi)=E1,
     diff(E2(c2,xi),c2,c2)=E2c2c2, diff(E2(c2,xi),xi,xi)=E2xixi,
     diff(E2(c2,xi),c2,xi)=E2c2xi, diff(E2(c2,xi),c2)=E2c2,
     diff(E2(c2,xi),xi)=E2xi, E2(c2,xi)=E2];
 

To save memory we shall use these substitutions and back substitutions for the exponential functions. The substitutions enable us to compute all exponential functions only once in one iteration step.

DE := [diff(E1(c1,xi),`$`(c1,2)) = E1c1c1, diff(E1(c1,xi),`$`(xi,2)) = E1xixi, diff(E1(c1,xi),c1,xi) = E1c1xi, diff(E1(c1,xi),c1) = E1c1, diff(E1(c1,xi),xi) = E1xi, E1(c1,xi) = E1, diff(E2(c2,xi),`$`(c...
DE := [diff(E1(c1,xi),`$`(c1,2)) = E1c1c1, diff(E1(c1,xi),`$`(xi,2)) = E1xixi, diff(E1(c1,xi),c1,xi) = E1c1xi, diff(E1(c1,xi),c1) = E1c1, diff(E1(c1,xi),xi) = E1xi, E1(c1,xi) = E1, diff(E2(c2,xi),`$`(c...

>    Esu:=[exp(xi/c1)=E1(c1,xi),exp(xi/c2)=E2(c2,xi)];
EBS:=subs(DE,map(u->rhs(u)=lhs(u),Esu));

Esu := [exp(xi/c1) = E1(c1,xi), exp(xi/c2) = E2(c2,xi)]

EBS := [E1 = exp(xi/c1), E2 = exp(xi/c2)]

>    Ebs:=subs(DE,subs(DE,Esu),simplify(remove(has,map(u->rhs(u)=lhs(u),
     [diff(Esu,c1,c1)[],diff(Esu,c2,c2)[],
      diff(Esu,xi,xi)[],
      diff(Esu,c1,xi)[],diff(Esu,c2,xi)[],
      diff(Esu,c1)[],diff(Esu,c2)[],
      diff(Esu,xi)[]]),0)));

Ebs := [E1c1c1 = xi*E1*(2*c1+xi)/c1^4, E2c2c2 = xi*E2*(2*c2+xi)/c2^4, E1xixi = 1/c1^2*E1, E2xixi = 1/c2^2*E2, E1c1xi = -E1*(c1+xi)/c1^3, E2c2xi = -E2*(c2+xi)/c2^3, E1c1 = -xi/c1^2*E1, E2c2 = -xi/c2^2*E...
Ebs := [E1c1c1 = xi*E1*(2*c1+xi)/c1^4, E2c2c2 = xi*E2*(2*c2+xi)/c2^4, E1xixi = 1/c1^2*E1, E2xixi = 1/c2^2*E2, E1c1xi = -E1*(c1+xi)/c1^3, E2c2xi = -E2*(c2+xi)/c2^3, E1c1 = -xi/c1^2*E1, E2c2 = -xi/c2^2*E...

>    s:=subs(Esu,s1+s2);  The whole sum of the residuals - for both functions

s := sum(M1[i]^2,i = 1 .. N1)-2*a1*sum(M1[i],i = 1 .. N1)+2/E1(c1,xi)/(c2+c1)*c1*a1*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)-2/E1(c1,xi)/(c2+c1)*c1*a2*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)+a1^2*N1-2/E1(c1,x...
s := sum(M1[i]^2,i = 1 .. N1)-2*a1*sum(M1[i],i = 1 .. N1)+2/E1(c1,xi)/(c2+c1)*c1*a1*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)-2/E1(c1,xi)/(c2+c1)*c1*a2*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)+a1^2*N1-2/E1(c1,x...
s := sum(M1[i]^2,i = 1 .. N1)-2*a1*sum(M1[i],i = 1 .. N1)+2/E1(c1,xi)/(c2+c1)*c1*a1*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)-2/E1(c1,xi)/(c2+c1)*c1*a2*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)+a1^2*N1-2/E1(c1,x...
s := sum(M1[i]^2,i = 1 .. N1)-2*a1*sum(M1[i],i = 1 .. N1)+2/E1(c1,xi)/(c2+c1)*c1*a1*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)-2/E1(c1,xi)/(c2+c1)*c1*a2*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)+a1^2*N1-2/E1(c1,x...
s := sum(M1[i]^2,i = 1 .. N1)-2*a1*sum(M1[i],i = 1 .. N1)+2/E1(c1,xi)/(c2+c1)*c1*a1*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)-2/E1(c1,xi)/(c2+c1)*c1*a2*sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)+a1^2*N1-2/E1(c1,x...

>    sm:=selectfun(s,sum);  There are 18 summations, but only 10 of them are unique. We shall collect them

sm := {sum(exp(T1[i]/c1),i = 1 .. N1), sum(exp(2*T1[i]/c1),i = 1 .. N1), sum(M2[i],i = 1 .. N2), sum(M2[i]^2,i = 1 .. N2), sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2), sum(exp(-T2[i]/c2),i = 1 .. N2), sum(ex...
sm := {sum(exp(T1[i]/c1),i = 1 .. N1), sum(exp(2*T1[i]/c1),i = 1 .. N1), sum(M2[i],i = 1 .. N2), sum(M2[i]^2,i = 1 .. N2), sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2), sum(exp(-T2[i]/c2),i = 1 .. N2), sum(ex...

>    s0:=remove(has,sm,[c1,c2]);  We shall compute coefficients independent summations separately

s0 := {sum(M2[i],i = 1 .. N2), sum(M2[i]^2,i = 1 .. N2), sum(M1[i]^2,i = 1 .. N1), sum(M1[i],i = 1 .. N1)}

>    Su0:=[seq(s0[j]=Z||j,j=1..nops(s0))];
Bs0:=map(u->rhs(u)=lhs(u),Su0);
 Substitutions and back substitutions for the coefficient independent sums

Su0 := [sum(M2[i],i = 1 .. N2) = Z1, sum(M2[i]^2,i = 1 .. N2) = Z2, sum(M1[i]^2,i = 1 .. N1) = Z3, sum(M1[i],i = 1 .. N1) = Z4]

Bs0 := [Z1 = sum(M2[i],i = 1 .. N2), Z2 = sum(M2[i]^2,i = 1 .. N2), Z3 = sum(M1[i]^2,i = 1 .. N1), Z4 = sum(M1[i],i = 1 .. N1)]

>    s1:=select(has,sm,c1);
s2:=select(has,sm,c2);
 The coefficient dependent summations

s1 := {sum(exp(T1[i]/c1),i = 1 .. N1), sum(exp(2*T1[i]/c1),i = 1 .. N1), sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1)}

s2 := {sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2), sum(exp(-T2[i]/c2),i = 1 .. N2), sum(exp(-2*T2[i]/c2),i = 1 .. N2)}

>    DU:=[diff(U1(c1),c1,c1)=U1c1c1,diff(U2(c1),c1,c1)=U2c1c1,
     diff(U3(c1),c1,c1)=U3c1c1,diff(U1(c1),c1)=U1c1,
     diff(U2(c1),c1)=U2c1,diff(U3(c1),c1)=U3c1,
     U1(c1)=U1,U2(c1)=U2,U3(c1)=U3];
DV:=[diff(V1(c2),c2,c2)=V1c2c2,diff(V2(c2),c2,c2)=V2c2c2,
     diff(V3(c2),c2,c2)=V3c2c2,diff(V1(c2),c2)=V1c2,
     diff(V2(c2),c2)=V2c2,diff(V3(c2),c2)=V3c2,
     V1(c2)=V1,V2(c2)=V2,V3(c2)=V3];
 Abbreviations for the summations and their derivatives. During iteration each parameter will be assigned to a numerical value, so we have to substitute derivatives by simple names.

DU := [diff(U1(c1),`$`(c1,2)) = U1c1c1, diff(U2(c1),`$`(c1,2)) = U2c1c1, diff(U3(c1),`$`(c1,2)) = U3c1c1, diff(U1(c1),c1) = U1c1, diff(U2(c1),c1) = U2c1, diff(U3(c1),c1) = U3c1, U1(c1) = U1, U2(c1) = U...
DU := [diff(U1(c1),`$`(c1,2)) = U1c1c1, diff(U2(c1),`$`(c1,2)) = U2c1c1, diff(U3(c1),`$`(c1,2)) = U3c1c1, diff(U1(c1),c1) = U1c1, diff(U2(c1),c1) = U2c1, diff(U3(c1),c1) = U3c1, U1(c1) = U1, U2(c1) = U...

DV := [diff(V1(c2),`$`(c2,2)) = V1c2c2, diff(V2(c2),`$`(c2,2)) = V2c2c2, diff(V3(c2),`$`(c2,2)) = V3c2c2, diff(V1(c2),c2) = V1c2, diff(V2(c2),c2) = V2c2, diff(V3(c2),c2) = V3c2, V1(c2) = V1, V2(c2) = V...
DV := [diff(V1(c2),`$`(c2,2)) = V1c2c2, diff(V2(c2),`$`(c2,2)) = V2c2c2, diff(V3(c2),`$`(c2,2)) = V3c2c2, diff(V1(c2),c2) = V1c2, diff(V2(c2),c2) = V2c2, diff(V3(c2),c2) = V3c2, V1(c2) = V1, V2(c2) = V...

>    Su1:=[seq(s1[j]=U||j(c1),j=1..nops(s1))];
Su2:=[seq(s2[j]=V||j(c2),j=1..nops(s2))];
Substitutions for the coeffcient dependent sums

Su1 := [sum(exp(T1[i]/c1),i = 1 .. N1) = U1(c1), sum(exp(2*T1[i]/c1),i = 1 .. N1) = U2(c1), sum(exp(T1[i]/c1)*M1[i],i = 1 .. N1) = U3(c1)]

Su2 := [sum(exp(-T2[i]/c2)*M2[i],i = 1 .. N2) = V1(c2), sum(exp(-T2[i]/c2),i = 1 .. N2) = V2(c2), sum(exp(-2*T2[i]/c2),i = 1 .. N2) = V3(c2)]

>    Bs1:=subs(DU,map(u->rhs(u)=simplify(lhs(u)),
       [diff(Su1,c1,c1)[],diff(Su1,c1)[],Su1[]]));
Bs2:=subs(DV,map(u->rhs(u)=simplify(lhs(u)),
       [diff(Su2,c2,c2)[],diff(Su2,c2)[],Su2[]]));
 and their back substitutions

Bs1 := [U1c1c1 = 1/c1^4*sum(T1[i]*exp(T1[i]/c1)*(2*c1+T1[i]),i = 1 .. N1), U2c1c1 = 4/c1^4*sum(T1[i]*exp(2*T1[i]/c1)*(c1+T1[i]),i = 1 .. N1), U3c1c1 = 1/c1^4*sum(T1[i]*exp(T1[i]/c1)*M1[i]*(2*c1+T1[i]),...
Bs1 := [U1c1c1 = 1/c1^4*sum(T1[i]*exp(T1[i]/c1)*(2*c1+T1[i]),i = 1 .. N1), U2c1c1 = 4/c1^4*sum(T1[i]*exp(2*T1[i]/c1)*(c1+T1[i]),i = 1 .. N1), U3c1c1 = 1/c1^4*sum(T1[i]*exp(T1[i]/c1)*M1[i]*(2*c1+T1[i]),...
Bs1 := [U1c1c1 = 1/c1^4*sum(T1[i]*exp(T1[i]/c1)*(2*c1+T1[i]),i = 1 .. N1), U2c1c1 = 4/c1^4*sum(T1[i]*exp(2*T1[i]/c1)*(c1+T1[i]),i = 1 .. N1), U3c1c1 = 1/c1^4*sum(T1[i]*exp(T1[i]/c1)*M1[i]*(2*c1+T1[i]),...

Bs2 := [V1c2c2 = -1/c2^4*sum(T2[i]*exp(-T2[i]/c2)*M2[i]*(2*c2-T2[i]),i = 1 .. N2), V2c2c2 = -1/c2^4*sum(T2[i]*exp(-T2[i]/c2)*(2*c2-T2[i]),i = 1 .. N2), V3c2c2 = -4/c2^4*sum(T2[i]*exp(-2*T2[i]/c2)*(c2-T...
Bs2 := [V1c2c2 = -1/c2^4*sum(T2[i]*exp(-T2[i]/c2)*M2[i]*(2*c2-T2[i]),i = 1 .. N2), V2c2c2 = -1/c2^4*sum(T2[i]*exp(-T2[i]/c2)*(2*c2-T2[i]),i = 1 .. N2), V3c2c2 = -4/c2^4*sum(T2[i]*exp(-2*T2[i]/c2)*(c2-T...
Bs2 := [V1c2c2 = -1/c2^4*sum(T2[i]*exp(-T2[i]/c2)*M2[i]*(2*c2-T2[i]),i = 1 .. N2), V2c2c2 = -1/c2^4*sum(T2[i]*exp(-T2[i]/c2)*(2*c2-T2[i]),i = 1 .. N2), V3c2c2 = -4/c2^4*sum(T2[i]*exp(-2*T2[i]/c2)*(c2-T...

>    S:=subs(Su0,Su1,Su2,s);  Substituted sum of the squared residuals

S := Z3-2*a1*Z4+2/E1(c1,xi)/(c2+c1)*c1*a1*U3(c1)-2/E1(c1,xi)/(c2+c1)*c1*a2*U3(c1)+a1^2*N1-2/E1(c1,xi)/(c2+c1)*c1*a1^2*U1(c1)+2/E1(c1,xi)/(c2+c1)*c1*a2*a1*U1(c1)+1/E1(c1,xi)^2/(c2+c1)^2*c1^2*a1^2*U2(c1)...
S := Z3-2*a1*Z4+2/E1(c1,xi)/(c2+c1)*c1*a1*U3(c1)-2/E1(c1,xi)/(c2+c1)*c1*a2*U3(c1)+a1^2*N1-2/E1(c1,xi)/(c2+c1)*c1*a1^2*U1(c1)+2/E1(c1,xi)/(c2+c1)*c1*a2*a1*U1(c1)+1/E1(c1,xi)^2/(c2+c1)^2*c1^2*a1^2*U2(c1)...
S := Z3-2*a1*Z4+2/E1(c1,xi)/(c2+c1)*c1*a1*U3(c1)-2/E1(c1,xi)/(c2+c1)*c1*a2*U3(c1)+a1^2*N1-2/E1(c1,xi)/(c2+c1)*c1*a1^2*U1(c1)+2/E1(c1,xi)/(c2+c1)*c1*a2*a1*U1(c1)+1/E1(c1,xi)^2/(c2+c1)^2*c1^2*a1^2*U2(c1)...
S := Z3-2*a1*Z4+2/E1(c1,xi)/(c2+c1)*c1*a1*U3(c1)-2/E1(c1,xi)/(c2+c1)*c1*a2*U3(c1)+a1^2*N1-2/E1(c1,xi)/(c2+c1)*c1*a1^2*U1(c1)+2/E1(c1,xi)/(c2+c1)*c1*a2*a1*U1(c1)+1/E1(c1,xi)^2/(c2+c1)^2*c1^2*a1^2*U2(c1)...

>    DA:=[diff(A1(c1,c2,xi),c1)=A1c1,diff(A1(c1,c2,xi),c2)=A1c2,
     diff(A1(c1,c2,xi),xi)=A1xi,A1(c1,c2,xi)=A1,
     diff(A2(c1,c2,xi),c1)=A2c1,diff(A2(c1,c2,xi),c2)=A2c2,
     diff(A2(c1,c2,xi),xi)=A2xi,A2(c1,c2,xi)=A2];
 During iteration we have to compute derivatives of the remaining two linear parameters  a1  and a2 . So we shall introduce substitutions for them and for their derivatives. We have to remember that these linear parameters will be a function of the nonlinear parameters c1 , c2  and xi .

DA := [diff(A1(c1,c2,xi),c1) = A1c1, diff(A1(c1,c2,xi),c2) = A1c2, diff(A1(c1,c2,xi),xi) = A1xi, A1(c1,c2,xi) = A1, diff(A2(c1,c2,xi),c1) = A2c1, diff(A2(c1,c2,xi),c2) = A2c2, diff(A2(c1,c2,xi),xi) = A...
DA := [diff(A1(c1,c2,xi),c1) = A1c1, diff(A1(c1,c2,xi),c2) = A1c2, diff(A1(c1,c2,xi),xi) = A1xi, A1(c1,c2,xi) = A1, diff(A2(c1,c2,xi),c1) = A2c1, diff(A2(c1,c2,xi),c2) = A2c2, diff(A2(c1,c2,xi),xi) = A...

>    a12:=subs(a1=A1(c1,c2,xi),a2=A2(c1,c2,xi),
       solve({diff(S,a1),diff(S,a2)},{a1,a2}));
 The remaining linear parametrs a1  and a2  are computed from the corresponding normal equations.

a12 := {A2(c1,c2,xi) = (E1(c1,xi)^2*Z1*c2^2*E2(c2,xi)^2*V3(c2)+E1(c1,xi)^2*c2^2*E2(c2,xi)^2*V3(c2)*Z4-E1(c1,xi)^2*c2^2*E2(c2,xi)^2*V1(c2)*V2(c2)-E1(c1,xi)^2*c2^2*E2(c2,xi)*V2(c2)*Z4-E1(c1,xi)^2*E2(c2,x...
a12 := {A2(c1,c2,xi) = (E1(c1,xi)^2*Z1*c2^2*E2(c2,xi)^2*V3(c2)+E1(c1,xi)^2*c2^2*E2(c2,xi)^2*V3(c2)*Z4-E1(c1,xi)^2*c2^2*E2(c2,xi)^2*V1(c2)*V2(c2)-E1(c1,xi)^2*c2^2*E2(c2,xi)*V2(c2)*Z4-E1(c1,xi)^2*E2(c2,x...
a12 := {A2(c1,c2,xi) = (E1(c1,xi)^2*Z1*c2^2*E2(c2,xi)^2*V3(c2)+E1(c1,xi)^2*c2^2*E2(c2,xi)^2*V3(c2)*Z4-E1(c1,xi)^2*c2^2*E2(c2,xi)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+E1^2*Z1*c2^2*E2^2*V3+E1^2*N2*c2^2*E2*V1+E1^2*c2^2*E2^2*V3*Z4-E1^2*Z1*c2^...

>    A12c1:=subs(DE,DU,DV,DA,diff(a12,c1)):

>    A12c2:=subs(DE,DU,DV,DA,diff(a12,c2)):

>    A12xi:=subs(DE,DU,DV,DA,diff(a12,xi)):  These derivatives will be used to create a set of three equations needed for Newton's method. Outputs are too long, so they are not displayed.

>   

>    Sc1:=subs(a1=A1(c1,c2,xi),a2=A2(c1,c2,xi),diff(S,c1)):  The normal equation Sc1(c1,c2,xi)  = Diff(S(a1,a2,c1,c2,xi),c1) = 0  for c1 . This equation is extremely nonlinear, so we shall use its linearized shape to compute c1, c2  and xi  fitting to this equation and similar equations Sc2(c1,c2,xi)  and Sxi(c1,c2,xi)  numerically, using Newton's method.

>    SC1C1:=subs(DE,DU,DV,DA,diff(Sc1,c1)):

>    SC1C2:=subs(DE,DU,DV,DA,diff(Sc1,c2)):

>    SC1XI:=subs(DE,DU,DV,DA,diff(Sc1,xi)):

>    SC1:=subs(DE,DU,DV,DA,Sc1):  

>   

>    Sc2:=subs(a1=A1(c1,c2,xi),a2=A2(c1,c2,xi),diff(S,c2)): The normal equation Sc2(c1,c2,xi)  = Diff(S(a1,a2,c1,c2,xi),c2) = 0  for c2 .

>    SC2C1:=subs(DE,DU,DV,DA,diff(Sc2,c1)):

>    SC2C2:=subs(DE,DU,DV,DA,diff(Sc2,c2)):

>    SC2XI:=subs(DE,DU,DV,DA,diff(Sc2,xi)):

>    SC2:=subs(DE,DU,DV,DA,Sc2):

>   

>    Sxi:=subs(a1=A1(c1,c2,xi),a2=A2(c1,c2,xi),diff(S,xi)): The normal equation Sxi(c1,c2,xi)  = Diff(S(a1,a2,c1,c2,xi),xi) = 0  for xi .

>    SXIC1:=subs(DE,DU,DV,DA,diff(Sxi,c1)):

>    SXIC2:=subs(DE,DU,DV,DA,diff(Sxi,c2)):

>    SXIXI:=subs(DE,DU,DV,DA,diff(Sxi,xi)):

>    SXI:=subs(DE,DU,DV,DA,Sxi):

>   

>   

>   

>   

>    err:=evalf(rand(-500..500)/25.): Data preparation

>    T:=[seq(j*2.,j=0..200),seq(j*5.,j=81..200)]: N:=nops(T);

N := 321

>    M:=[seq(evalf(subs(t=T[j],g+err()),4),j=1..N)]:

>    Digits:=20:

>    P1:=plot([seq([T[i],M[i]],i=1..N)],style=point,symbol=circle,color=gray):

>    P1;  Plot of given data

[Maple Plot]

>    c1:=250.: c2:=450.: xi:=470.: dc1i:=1.; dc2i:=1.; dxii:=1.; n:=0; Start:=time();  the initial values for the iteration

dc1i := 1.

dc2i := 1.

dxii := 1.

n := 0

Start := 8.774

>    while max(abs(dc1i/c1),abs(dc2i/c2),abs(dxii/xi))>10^(-5) do;  Iteration procedure
  n:=n+1:
 Count of the steps
  T1:=map(u->`if`(u<=xi,u,NULL),T):
 Splitting of data into data sets for the first and second function

>      N1:=nops(T1):

>      M1:=M[1..N1]:

>      T2:=T[N1+1..N]:

>      M2:=M[N1+1..N]:

>      N2:=nops(T2):
  EBF:=evalf(EBS);

>      Ebf:=[subs(EBF,Ebs)[],EBF[]];  Substitution of the numerical values of exponential functions and summations and their derivatives  
  Bf0:=evalf(Bs0);
  Bf1:=evalf(Bs1);
  Bf2:=evalf(Bs2);

>      A12s:=subs(Ebf,Bf0,Bf1,Bf2,A12):  The numerical values of a1  and a2 and their derivatives

>      A12c1s:=subs(Ebf,Bf0,Bf1,Bf2,A12c1):

>      A12c2s:=subs(Ebf,Bf0,Bf1,Bf2,A12c2):

>      A12xis:=subs(Ebf,Bf0,Bf1,Bf2,A12xi):

>      SC1s:=subs(Ebf,Bf0,Bf1,Bf2,A12s,SC1):

>      SC1C1s:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12c1s,SC1C1):

>      SC1C2s:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12c2s,SC1C2):

>      SC1XIs:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12xis,SC1XI):

>      EQ1:=SC1s+SC1C1s*dc1+SC1C2s*dc2+SC1XIs*dxi: Sc1(c1,c2,xi)  linearized, dc1 , dc2  and dxi  are corrections, (increments) to the c1, c2 and xi .

>      SC2s:=subs(Ebf,Bf0,Bf1,Bf2,A12s,SC2):

>      SC2C1s:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12c1s,SC2C1):

>      SC2C2s:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12c2s,SC2C2):

>      SC2XIs:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12xis,SC2XI):

>      EQ2:=SC2s+SC2C1s*dc1+SC2C2s*dc2+SC2XIs*dxi: Sc2(c1,c2,xi)  linearized, dc1 , dc2  and dxi  are corrections, (increments) to the c1, c2 and xi .

>      SXIs:=subs(Ebf,Bf0,Bf1,Bf2,A12s,SXI):

>      SXIC1s:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12c1s,SXIC1):

>      SXIC2s:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12c2s,SXIC2):

>      SXIXIs:=subs(Ebf,Bf0,Bf1,Bf2,A12s,A12xis,SXIXI):

>      EQ3:=SXIs+SXIC1s*dc1+SXIC2s*dc2+SXIXIs*dxi: Sxi(c1,c2,xi)  linearized, dc1 , dc2  and dxi  are corrections, (increments) to the c1, c2 and xi .

>      sol:=solve({EQ1,EQ2,EQ3},{dc1,dc2,dxi}):  The corrections for c1 , c2  and xi

>      xi:=xi+subs(sol,dxi); dxii:=subs(sol,dxi):

>      c1:=c1+subs(sol,dc1); dc1i:=subs(sol,dc1):

>      c2:=c2+subs(sol,dc2); dc2i:=subs(sol,dc2):

>      FT1:=subs(a1=A1,a2=A2,A12s,f1(t)):  Prepare functions for a plot of the iteration step  
  FT2:=subs(a1=A1,a2=A2,A12s,f2(t)):

>      Y0:=evalf(subs(t=xi,FT1)):

>      Title:=cat(`Step=`,n,`,  Time=`,convert(time()-Start,string),`sec`):

>      display({plot(FT1,t=0..xi,color=red,thickness=3),
           plot(FT2,t=xi..T[N],color=blue,thickness=3),
           plot([[0,Y0],[xi,Y0],[xi,0]],color=black),P1},title=Title):
  print(%);

>      print(evalf(['c1'=c1,'dc1'=dc1i,'c2'=c2,'dc2i'=dc2i,'xi'=xi,'dxii'=dxii][],8));

>      print(`Max. relative step`= max(abs(dc1i/c1),abs(dc2i/c2),abs(dxii/xi)));
od:
 If the relative corrections are too big, repeat iteration

[Maple Plot]

c1 = 226.65063, dc1 = -23.349372, c2 = 353.11105, dc2i = -96.888955, xi = 431.65546, dxii = -38.344540

`Max. relative step` = .27438664370557370514

[Maple Plot]

c1 = 222.94330, dc1 = -3.7073306, c2 = 424.11951, dc2i = 71.008463, xi = 420.57813, dxii = -11.077330

`Max. relative step` = .16742559945070624462

[Maple Plot]

c1 = 207.30286, dc1 = -15.640433, c2 = 496.95041, dc2i = 72.830904, xi = 400.32767, dxii = -20.250459

`Max. relative step` = .14655567649338078472

[Maple Plot]

c1 = 206.33738, dc1 = -.96548714, c2 = 528.32901, dc2i = 31.378599, xi = 396.46017, dxii = -3.8674961

`Max. relative step` = .59392155109840770438e-1

[Maple Plot]

c1 = 205.23094, dc1 = -1.1064388, c2 = 536.81233, dc2i = 8.4833180, xi = 394.88342, dxii = -1.5767493

`Max. relative step` = .15803135547819383312e-1

[Maple Plot]

c1 = 205.09613, dc1 = -.13480949, c2 = 537.40308, dc2i = .59074684, xi = 394.73787, dxii = -.14555921

`Max. relative step` = .10992621067943888298e-2

[Maple Plot]

c1 = 205.09613, dc1 = .50455884e-6, c2 = 537.40431, dc2i = .12334608e-2, xi = 394.73776, dxii = -.10664898e-3

`Max. relative step` = .22952194248300197454e-5

>    alias(H=Heaviside):  Abbreviation for the Heaviside  function

>    FT:=FT1*H(xi-t)+FT2*H(t-xi);  The resulting function

FT := (4.4491975287365876593+33.341984197140482634*exp(.48757624352545080399e-2*t))*H(394.73775874765792825-t)+(831.61866786880007928-1247.9574426006670791*exp(-.18607963934343327363e-2*t))*H(-394.7377...
FT := (4.4491975287365876593+33.341984197140482634*exp(.48757624352545080399e-2*t))*H(394.73775874765792825-t)+(831.61866786880007928-1247.9574426006670791*exp(-.18607963934343327363e-2*t))*H(-394.7377...

>    plot(FT-g,t=T[1]..T[N],title=`Mass difference`);  Difference between new function FT  and Gompertz function g

[Maple Plot]

>    plot({diff(FT,t),diff(g,t)},t=T[1]..T[N],title=`Mass increment`);

[Maple Plot]

>    Mf:=evalf(map(u->subs(t=u,FT),T),4):  Numerical values of the new function FT  at times T[i]

>    with(stats):

>    Correlation:=describe[linearcorrelation](Mf,M);  Coefficient of the linear correlation between measured mass M[i]  and computed mass FT(M[i]) .

Correlation := .99813339016018067009

>   

Acknowledgement:

Author would like to thank to Autocont Brno and Waterloo Maple for their continuous interest and support.