Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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!

share|improve this question
2  
After loading your code, I saw that at least fexp1tand fexp1 are 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:44
NDSolve returns a list of solutions. You should take the First element of it. – Xerxes Feb 24 at 6:45
@ belisarius, Hi Thanks for your comment. I defined 'fexp1t' and 'fexp' in my 'data entry'. Did I do it wrong? @Xerxes: Thanks. I added '// First'. But I still got the same error message. – DumbleKo Feb 24 at 6:58
Sorry, I haven't seen that code block. – belisarius Feb 24 at 7:25
@DumbleKo It works for me. The function has trouble finding a minimum because your chi2 appears to not depend on D2 for much of the range of the function. There's a shallow minimum near 0.0015,0.0018, but instability in the NDSolve tends to confuse things in that region. – Xerxes Feb 24 at 8:35

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.