Hi Everybody,
I just stumbled upon a problem and cannot move forward, so I'd kindly appreciate your expertise and help. I am trying to perform a simultaneous fit of functions, which are a solution of a set of differential equations. One of the parameters of the fit enters also as a parameter for a starting value in NDSolve ad thus I get an error (initial condition being non-numeric). The fitting is performed by constructing and minimizing a function (a sum of squares). Here's the code below.
The function is defined here:
ClearAll[Ae, A2e, Ah, A2h, DE, T]; Ts = 10;
funk[Ae_?NumberQ, A2e_?NumberQ, Ah_?NumberQ, A2h_?NumberQ,
DE_?NumberQ, Tx_?NumberQ] :=
Block[
{uu, nx, nd, nxp, nxm, n2x},
uu = NDSolve[{
nx[T]' == -Ae nx[T] - Ah nx[T] + A2h nxp[T] + A2e nxm[T] + Exp[-(DE/(2 kbev T))] nd[T] - Exp[DE/(2 kbev T)] nx[T],
nd[T]' == -Ae nd[T] - Ah nd[T] + A2h nxp[T] + A2e nxm[T] - Exp[-(DE/(2 kbev T))] nd[T] + Exp[DE/(2 kbev T)] nx[T],
nxp[T]' == -Ae nxp[T] - A2h nxp[T] + A2e n2x[T],
nxm[T]' == -A2e nxm[T] - Ah nxm[T] + A2h n2x[T],
n2x[T] == -A2e n2x[T] - A2h n2x[T],
nx[Ts] == Exp[-(DE/(2 kbev Ts))],
nd[Ts] == Exp[DE/(2 kbev Ts)], nxp[Ts] == nx[Ts],
nxm[Ts] == nx[Ts], n2x[Ts] == nx[Ts]/2}, {nx[T], nd[T], nxp[T],
nxm[T], n2x[T]}, {T, 10, 100}][[1]];
{nx[T], nxp[T], nxm[T], n2x[T]} /. uu /. {T -> Tx}
];
This is data (for tests only):
osT = {10, 25}; daneX = {1, 0.8}; daneXp = {0.9, 0.3}; daneXm = {1,
0.8}; dane2X = {0.5, 0.1};
And this is the function to be minimized:
sse[Ae_, A2e_, Ah_, A2h_, DE_] :=
Apply[Plus, (funk[Ae, A2e, Ah, A2h, DE, osT][[1]] - daneX)^2 +
(funk[Ae, A2e, Ah, A2h, DE, osT][[2]] - daneXp)^2 +
(funk[Ae, A2e, Ah, A2h, DE, osT][[3]] - daneXm)^2 +
(funk[Ae, A2e, Ah, A2h, DE, osT][[4]] - dane2X)^2];
I can evaluate sse, but running FindMinimum results with the error:NDSolve::ndinnt: Initial condition 0.+0.5` 2.71828^(-580.248 DE) is not a number or a rectangular array of numbers.
Any ideas would be much appreciated,
Cheers
EB