Re: Why this function does not return a single value
- To: mathgroup at smc.vnet.net
- Subject: [mg60313] Re: Why this function does not return a single value
- From: Marek Bromberek <marekbr at gmail.com>
- Date: Sat, 10 Sep 2005 22:36:37 -0400 (EDT)
- References: <dfueac$1tf$1@smc.vnet.net>
- Reply-to: marekbr at gmail.com
- Sender: owner-wri-mathgroup at wolfram.com
Thanks Bill for Your reply. It makes a few things clear. I do understand
that using a[1] in pattern matching probably does not make sense.
Disregarding whether one thinks of it as a first element of an array or a
function evaluated at 1. However I would expect Mathematica will return an
error or a warning of some kind in this case.
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
Bill Rowe wrote:
> On 9/9/05 at 4:07 AM, marekbr at gmail.com (Marek) wrote:
>
>>I know that Mathematica treats space as a multiplication sign. What
>>happens here is that when I remove the multiplication signs in Input
>>mode, convert to Standard mode and then back to Input mode the
>>multiplication signs reappear. I just did the following experiment.
>>Opened fresh Mathematica notebook and typed in (in Standard mode)
>>g[x_,a[1]_]:=a*x (no spaces anywhere) Executed that Then converted to
>>Input mode and there will be a star between a[1] and the blanc sign _ .
>
> In essence, g[x_,a[1]_]:= a*x is meaningless. This defines a function
> named g having an arbitrary first arguement you are naming x, an arbitrary
> second argument you are naming as the function a evaluated at 1 returning
> the product of the function and the first argument. Is this really what
> you want?
>
> Perhaps, you want to create a function that returns the product of
> somehing and the first element of something else. That could be simply
> done as
>
> g[x_, a_]:= x*First[a]
>
> Or perhaps you want to return the product of something an a function
> evaluated at 1. That could be done as
>
> g[x_,a_]:= x*a[1]
> --
> To reply via email subtract one hundred and four