Re: Why this function does not return a single value

• To: mathgroup at smc.vnet.net
• Subject: [mg60326] Re: Why this function does not return a single value
• Date: Tue, 13 Sep 2005 06:07:02 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 9/10/05 at 10:36 PM, marekbr at gmail.com (Marek Bromberek) wrote:

>Let me explain what I want to do (probably it was not entirely
>clear from my original post). I want to fit a sum of 15 Voight
>functions to a dataset. Initially I thought that by making all the
>parameters as an array I would be able to use Sum function so that
>a[i], b[i] and c[i] would refer to the parameters of i-th peak in
>the sum. However I could not get this to work. (see my original
>post). Following Paul's suggestions I did the following

>I defined the Voigt function

>Voigt[x_, (a_)?NumericQ, (b_)?NumericQ, (\[Delta]L_)?NumericQ,
>(\[Delta]G_)?NumericQ] :=
>(a*(2.*Log[2.]*\[Delta]L)*NIntegrate[1/(E^t^2*(((Sqrt[Log[2.]]*\[
>Delta]L)/\[Delta]G)^2 + ((Sqrt[4.*Log[2.]]*(x - b))/\[Delta]G -
>t)^2)), {t, -Infinity, Infinity}])/(Pi^(3/2)*\[Delta]G)

>then I defined lists of parameters

>a = {6224., 2122., 1936., 4261., 7275., 19059., 5057., 3209.,
>3586., 3792.,
>6182., 1993., 1615., 737., 3114.};
>b = {5.49, 9.87, 11.17, 13.91, 14.83, 16.92, 17.91, 19.44, 21.91,
>22.8, 23.9, 26.0, 29.75, 30.97, 33.99}; \[Delta]L = {0.5, 0.5, 0.5,
>0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5};
>\[Delta]G = {0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
>0.5, 0.5, 0.5, 0.5};

>Then I defined another function for plotting purposes like so:

>Fu[x_] := Plus @@ Thread[Voigt[x, a, b, \[Delta]L, \[Delta]G]]

>And that allows me to plot what I want

>Plot[Fu[x] + 4680.*Exp[(-Log[2.])*((x - 27.4)^2/15^2)] +
>6569*Exp[-x/2.57], {x, 0, 40}, ImageSize -> {600, 400}, PlotRange
>-> All]

>But I have no idea how to do the NonlinearFit with that function.
>Any help would be greatly appreciated

It still isn't clear to me what it is you want to do. Your code defines parameters for 15 instances of your function which you sum. You say you are trying to fit this sum to a data set using NonlinearFit. But you don't really explain what you mean by fitting this sum to a data set. What does your data set look like? What unknown parameters are you trying to esitmate?

As an aside, I will mentiion the functionality of NonlinearFit is fully contained in the built in function FindFit. I suspect (but haven't verified) FindFit will be faster than NonlinearFit. Also, FindFit has a bit more flexibility in that it provides for a mechanism to monitor convergence and allows for different norms.

--
To reply via email subtract one hundred and four

```

• Prev by Date: Why am I getting this error?
• Next by Date: Set of strings reducing problem (Again!)
• Previous by thread: Re: Why this function does not return a single value
• Next by thread: Re: Why this function does not return a single value