[Date Index]
[Thread Index]
[Author Index]
inability to pass argument(s) to functions..
*To*: mathgroup at smc.vnet.net
*Subject*: [mg29878] inability to pass argument(s) to functions..
*From*: "Mark Harder" <harderm at ucs.orst.edu>
*Date*: Mon, 16 Jul 2001 00:28:50 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Just to set the stage, I am trying to use NonlinearRegression
(again, alas) to fit a model with shared parameters to 2 sets of data,
which are distinguished from each other by an integer index which
appears in the data list in the NLR arguments as an extra independent
variable, which will be passed to the model function in the usual
fashion. This simple scheme fails, although I have tried several
alternative formulations of the model function because, apparently, NLR
is unable to pass the integer index into the model function. I have
enclosed a trial function which reproduces this behavior. I hope
someone can show me what I am doing "wrong" and how I can fix my
problem:
(* definition of function *)
In[478]:=
Clear[trialfn, i, ii, c, cc];
trialfn[aN_List, c, i] := (Print[i];
Return[c*aN\[LeftDoubleBracket]i\[RightDoubleBracket]] )
(* aN is a list *)
In[405]:= {aN1,aN2};
{c, i, aN}
Out[405]= {c, i, {aN1, aN2}}
(* pass numeric values explicitly *)
In[482]:=
trialfn[{-3.4, -4.}, 0., 1 ]
Out[482]=
trialfn[{-3.4, -4.}, 0., 1] (* Doesn't understand command *)
(* passed by replacement ( I think this is how NLR does it) *)
In[487]:=
trialfn[aN, c, i ] /. {aN1 -> -3.4`, aN2 -> -4.`, c -> 1.`, i -> 2`}
an integer nor a list \
of integers."
Out[487]= -4. (* correct evaluation, for i=2!! *)
note the result of printing out the value of i, although the function
*is* evaluated. This doesn't work in NLR, however:
fitData2 = {{0, 1, -3.320248485`}, {1, 1, -3.215648485`}, {2,
1, -3.375939394`}, {0, 2, -4.312424242`}, {1, 2, -3.985844444`},
{2,
2, -4.300822222`}}; (* trial data for fitting *)
In[476]:= best3D = NonlinearRegress[fitData2, trialfn[aN, c, i ]
,
{c, i}, { {aN1, {-3.4, -3.}}, {aN2, {-4., -3.}} },
Method -> Gradient, Compiled -> False]
an integer nor a list \
of integers.
"From In[476]:=
FindMinimum::"fmgs": "Could not symbolically find the gradient of
\!\(#1\\ \(\
\(\(\({aN1, aN2}\)\) \[LeftDoubleBracket] #2
\[RightDoubleBracket]\)\)\). Try \
using the default method, giving two starting values for each variable."
.... and a long list of repeating error messages ending with the
unevaluated output.
Thanks,
mark e. harder
Prev by Date:
**FindRoot question**
Next by Date:
**Re: Memory Conservation**
Previous by thread:
**Re: Re: FindRoot question**
Next by thread:
**Re: inability to pass argument(s) to functions..**
| |