I'm just wondering if someone could help me solve NMinimize::nnum: problem? I still can't find a solution for it. I used NDSolve to solve my functions. And trying to use it to fit to my data to obtain D1 and D2. (which should range 10^-4 to 10^-2). Here are functions:
First, I need to obtain solution of cfs1, cfh1 & css1, csh1 from two equations using Solve:
solf1 = Solve[cfs == Kex*s0[t]*hf[t]^4*(c0 - 2*cfs - cfh)^2 &&
cfh == Keh*hf[t]^2*(c0 - 2*cfs - cfh), {cfs, cfh}];
cfs1 = First[Evaluate[cfs] /. solf1];
cfh1 = First[Evaluate[cfh] /. solf1];
sols1 = Solve[cfs == Kex*sl[t]*hl[t]^4*(c0 - 2*cfs - cfh)^2 &&
cfh == Keh*hl[t]^2*(c0 - 2*cfs - cfh), {cfs, cfh}];
css1 = First[Evaluate[cfs] /. sols1];
csh1 = First[Evaluate[cfh] /. sols1];
Then I use solution from above and applied it to NDSolve, to obtained solution for s0 and s1. But first enter all the constant:
V = 40;
A = 0.95*.4;
D1 = 1.61*10^-3;
D2 = 1.85*10^-3;
L = .0038;
Kex = .055;
Keh = 0.194;
c0 = 1;
Entered my data:
fexp1= {0.020, 0.017, 0.014, 0.012, 0.011, 0.009, 0.008, 0.008, 0.007};
fexp1t = {0, 60, 120, 180, 240, 300, 360, 420, 480};
Then try to fit by NDSolve:
Clear[D1, D2];
Equation[D1_?NumberQ,
D2_?NumberQ] = {V*s0'[t] == (-A*D1)/L*(cfs1 - css1),
V*sl'[t] == (A*D1)/L*(cfs1 - css1),
V*hf'[t] == (-A*D2)/L*(cfh1 - csh1),
V*hl'[t] == (A*D2)/L*(cfh1 - csh1),
s0[0] == 0.0205, sl[0] == 10^-10, hf[0] == 4, hl[0] == 0.001};
Clear[chi2];
chi2[D1_?NumberQ,
D2_?NumberQ] := (sol =
s0 /. NDSolve[Equation[D1, D2], {s0, sl, hf, hl}, {t, 0, 2000},
MaxSteps -> Infinity]// First;
(sol /@ fexp1t) - fexp1 // #.# &)
Apply NMinimize, but obtained an error NMinimize::nnum: message:
NMinimize[{chi2[D1, D2], D1 > 0, D2 > 0}, {D1, D2}]
"NMinimize::nnum: The function value ..... is not a number at {D1,D2} = {1.91862,1.66351}."
Thanks for reading this. And please let me know if I miss out any information!
fexp1tandfexp1are undefined. I suggest you to load your posted code in a fresh Mma session and run it to be sure other users could run it too – belisarius Feb 24 at 6:44NDSolvereturns a list of solutions. You should take theFirstelement of it. – Xerxes Feb 24 at 6:45