       FindMinimum and Module

• To: mathgroup at smc.vnet.net
• Subject: [mg113120] FindMinimum and Module
• From: Versiane UFOP <versiane.ufop at gmail.com>
• Date: Wed, 13 Oct 2010 23:26:43 -0400 (EDT)

```Dear Mathematica users

I would like to request any help with the code below, which I have been
struggling in the last couple of weeks. I am trying to use FindMinimum
to find the best k value that fits experimental data (extração) using
the code enclosed in a Module structure. This is a heterogeneous
kinetics problem where the Shrinking Core Model is modified to
incorporate particle size distribution and k is a rate constant. As many
of you always express here FindRoot does not produce the expected
outcome and give the standard message ""The function value...is not a
real number at {k} = {0.03`}". I would very much appreciate any help.

The code is:

mean := 100;
std := 10;
a = 5.032;
b = 2.974;
dmax = 190;
u = 1;

extração = {{0, 0.}, {10, 0.068973}, {20, 0.105011}, {30, 0.127376},
{40, 0.152779}, {50, 0.177607}, {60, 0.186656}, {80, 0.224261}, {100,
0.25433}, {120, 0.275795}}

f[D_] := (1/(b^a*Gamma[a]))*D^(a - 1)*Exp[-D/b]

t := Table[extração[[i, 1]], {i, Length[extração]}]

model = ConstantArray[0, {Length[extração]}]

conversion[(k_)?NumericQ] := Module[{dmin, rn, n, d, y, w, unconvt},
For[j = 1, j <= Length[t], j++,
dmin = (k*t[[j]])^0.5;
rn = (dmax - dmin)/(2*u) + 1; n = Round[rn];
d = Table[dmin + (2*i - 1)*u, {i, n}];
w = Table[y /. FindRoot[1 - 3*(1 - y)^(2/3) + 2*(1 - y) ==
(k/d[[i]]^2)*t[[j]], {y, 0.3}], {i, n}];
unconvt =     1 - Sum[(1 - w[k][[i]])*N[Integrate[f[D], {D, d[[i]] -
u, d[[i]] + u}]], {i, 1, n}];
model[[j]] = unconvt; ];
model1 = {t, model};
x = Transpose[model1]; ]
fit[(k_)?NumericQ] :=  Sum[(conversion[k][extração[[i, 1]]] -
extração[[i, 2]])^2, {i, 1, Length[extração]}];

FindMinimum[{fit[k], k > 0}, {k, 0.03}]

--
Prof. Versiane Albis Leão
Bio&Hidrometallurgy Laboratories
Department of Metallurgical and Materials Engeng.
Universidade Federal de Ouro Preto, Brazil.

```

• Prev by Date: Re: Programing tips: What is faster?
• Next by Date: Is there any available implementation of Prim's algorithm?