Gauss-Newton

GaussNewton[r_,p0_,tol_,stop_]:=(
Module[{s},
iter=0;
temp=If[Length[p0]==1,{},Table[0,Length[p0]-1]];
ϵ=(10^(-6));
Jacobi[p_]:=Table[(1/ϵ)(r[p+Insert[temp,ϵ,k]][[s]]-r[p][[s]]),{s,1,Length[r[p]]},{k,1,Length[p]}]//Simplify;
pOld=p0;
pNew=p0+Table[0.1,{k,Length[p0]}];

While[Norm[pOld-pNew]>tol && iter≤stop ,
pOld=pNew;
Δp=LeastSquares[Jacobi[pOld],-r[pOld]];
α=1;
pNew=pOld+α Δp;
While[Norm[r[pNew],2]>Norm[r[pOld],2],
α/=2;
pNew=pOld+α Δp;
];
iter++;
];
pNew
]
)

Diffusion parameter estimation

HeatEquation[d_,T_,l_,h_]:=(
τ=Min[Abs[h^2 /(4d)],0.01];
n=Ceiling[l/h];
m=Ceiling[T/τ];
t=Table[(j-1)τ,{j,1,m+1}];
x=Table[(i-1)h,{i,1,n+1}];
y=Table[0,{i,1,n+1},{j,1,m+1}];
(*initial condition*)
For[i=1,i≤ n+1,i++,
y[[i,1]]=Sin[2 Pi (i-1)h];
];
For[j=1,j≤ m,j++,
For[i=2,i≤ n,i++,
y[[i,j+1]]=(1-2d τ/h^2) y[[i,j]]+d τ/h^2 (y[[i-1,j]]+y[[i+1,j]]);
];
y[[1,j+1]]=0;
y[[n+1,j+1]]=0;
];
y
)

res[D_]:=(
d=D[[1]];
y=HeatEquation[d,T,l,h];
interpolation=Interpolation[Flatten[Table[{x[[i]],t[[j]],y[[i,j]]},{i,Length[x]},{j,Length[t]}],1]];
Join[Table[interpolation[x[[i]],1]-u1[[i]],{i,Length[x]}],Table[interpolation[x[[i]],2]-u2[[i]],{i,Length[x]}]]
);

T=2;
l=1;
h=0.2;
tol=(10^(-5));
stop=100;
u1={0,0.6,0.45,-0.4,-0.6,0};
u2={0,0.4,0.3,-0.27,-0.47,0};
diff=GaussNewton[res,{0.1},tol,stop]
solution=HeatEquation[diff,T,l,h];
x=Range[0,1,0.2];

Show[ListPlot[Transpose[{x,u1}],PlotStyle-> Red,PlotRange-> {{0,1.1},{-1,1}}],
ListPlot[Transpose[{x,Flatten[solution[[All,101]]]}],PlotStyle-> Black]
]

Show[ListPlot[Transpose[{x,u2}],PlotStyle-> Red,PlotRange-> {{0,1.1},{-1,1}}],
ListPlot[Transpose[{x,Flatten[solution[[All,201]]]}],PlotStyle-> Black]
]

Monod model

resid[p_]:=(
Module[{s,x},
a=p[[1]];
b=p[[2]];
s0=p[[3]];
x0=p[[4]];
Res[t_]={s[t],x[t]}/.NDSolve[{s'[t]==1-s[t]- a s[t]/(b+s[t]) x[t],x'[t]== (a s[t]/(b+s[t])-1)x[t],s[0]== s0,x[0]== x0},{s,x},{t,0,2}][[1]];
Join[Res[Range[0,2,0.5]][[1]],Res[Range[0,2,0.5]][[2]]]-{1,1,0.87,0.52,0.04,0.01,0.04,0.14,0.48,0.965}
]
)

tol=(10^(-6));
stop=50;
GaussNewton[resid,{1000,1000,1,0},tol,stop]

Clear[s,x];
a=pNew[[1]];
b=pNew[[2]];
s0=pNew[[3]];
x0=pNew[[4]];
solution=NDSolve[{s'[t]==1-s[t]- ((a  s[t])/(b+s[t])) x[t],x'[t]== (((a s[t])/(b+s[t]))-1)x[t],s[0]== s0,x[0]== x0},{x,s},{t,0,2}][[1]];
x[t_]=x[t]/.solution[[1]];
s[t_]=s[t]/.solution[[2]];

Show[ListPlot[Transpose[{Range[0,2,0.5],{1,1,0.87,0.52,0.04}}]],Plot[s[i],{i,0,2},PlotRange->All]]

Show[ListPlot[Transpose[{Range[0,2,0.5],{0.01,0.04,0.14,0.48,0.965}}]],Plot[x[i],{i,0,2},PlotRange->All],PlotRange-> All]