       Re: Perplexed by the behavior of NonlinearFit in Mathematica ver 4.2 vs 5.1

• To: mathgroup at smc.vnet.net
• Subject: [mg54359] Re: Perplexed by the behavior of NonlinearFit in Mathematica ver 4.2 vs 5.1
• From: "George Ellis" <ellisg at rogers.com>
• Date: Sat, 19 Feb 2005 02:32:05 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

Thank you.  (Red face & much embarassment).  However, I really appreciate
you taking the time to respond to a "User Brain Failure" post.

George
----- Original Message -----
From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
To: mathgroup at smc.vnet.net
Subject: [mg54359] [Bulk] [mg54303] Re: Perplexed by the behavior of NonlinearFit in
Mathematica ver 4.2 vs 5.1

> Hi,
>
> you mean
>
> << "Statistics`"
> << "Graphics`"
>
> Clear[nlr]
> pop = {1650, 1750, 1860,
> 2070, 2300, 2560, 3040,
> 3710, 4450, 5280, 6080};
> nlr[t_] = NonlinearFit[pop,
> E^(theta*t)*k, {t},
> {theta, k}]
>
> Table[nlr[t], {t, 0, 3}]
> Table[Evaluate[nlr[t]],
> {t, 0, 3}]
> Table[nlr[t] /. t -> i,
> {i, 0, 3}]
>
> where nrl[] is define without the SetDelayed[], otherwise
>
> the nonlinear fit is performed for every new t-value, if it is a
>
> numeric value like nlr you can't use it in NonlinearFit[] because it is
> not
>
> a valid variable.
>
>
>
> Regards
>
>  Jens
>
> "G Ellis" <ellisg at rogers.com> schrieb im Newsbeitrag
> news:cup61t\$dvj\$1 at smc.vnet.net...
>> Please note that my questions are at the end of this Post.  What
>> follows is some necessary background:
>>
>> I include below a NonlinearFit function ("nlr[t]"), which I created in
>> ver 4.2 of Mathematica.  It is VERY simple.  I plotted the function
>> and the graph was what I expected. However, I never looked at
>> tabulated results of the function and therefore I did not notice a
>> peculiar issue with my syntax.    It was only when I ran the code in
>> ver 5.1 that I saw the odd output.  (The code below includes
>> tabulations that I created after I noticed the different behavior
>> between ver 4.2 and ver 5.)
>>
>> In ver 4.2 Mathematica does not "complain" about the function "nlr[t]"
>> in the following.  It appears to plot the result correctly; but it
>> returns different "Table" results without and with "Evaluate".  I
>> believe the correct results are those returned with "Evaluate" or the
>> use of the "ReplaceAll" function.
>>
>> In:=
>> << "Statistics`"
>> << "Graphics`"
>> In:=
>> \$Version
>> Out=
>> "4.2 for Microsoft Windows \
>> (June 5, 2002)"
>> In:=
>> pop = {1650, 1750, 1860,
>>    2070, 2300, 2560, 3040,
>>    3710, 4450, 5280, 6080};
>> nlr[t_] := NonlinearFit[pop,
>>   E^(theta*t)*k, {t},
>>   {theta, k}]
>> t1 = Table[nlr[t], {t, 0, 3}]
>> t1 = Table[Evaluate[nlr[t]],
>>   {t, 0, 3}]
>> t2 = Table[nlr[t] /. t -> i,
>>   {i, 0, 3}]
>> Out=
>> {537.6363636363639,
>>  3158.987930628625,
>>  1531.0837992793613,
>>  1782.0476907177406}
>> Out=
>> {1130.2076401682348,
>>  1315.4628872314652,
>>  1531.0837992793613,
>>  1782.0476907177406}
>> Out=
>> {1130.2076401682348,
>>  1315.4628872314652,
>>  1531.0837992793613,
>>  1782.0476907177406}
>>
>> p1 = Plot[nlr[t], {t, 0, 11}, PlotStyle -> IndianRed];
>> p2 = Plot[nlr[t] /. t -> i, {i, 0, 11},
>>    PlotStyle -> EmeraldGreen];
>>
>> In ver 5.1, Mathematica will not let me evaluate "nlr[t]" directly.
>> (This is good, I think).  It forces the use of "Evaluate".
>>
>> \$Version
>> "5.1 for Microsoft Windows \
>> (October 25, 2004)"
>> pop = {1650, 1750, 1860,
>>    2070, 2300, 2560, 3040,
>>    3710, 4450, 5280, 6080};
>> nlr[t_] := NonlinearFit[pop,
>>   E^(theta*t)*k, {t},
>>   {theta, k}]
>> Table[nlr[t], {t, 0, 3}]
>> Table[Evaluate[nlr[t]],
>>  {t, 0, 3}]
>> Table[nlr[t] /. t -> i,
>>  {i, 0, 3}]
>> \!\(\*
>>  RowBox[{\(General::"ivar"\),
>>    ":", "\<\"\\!\\(0\\) is not a valid variable.
>> \\!\\(\\*ButtonBox[\\\"More\
>> ButtonFrame->None, \
>> ButtonData:>\\\"General::ivar\\\"]\\)\"\>"}]\)
>> NonlinearFit::fitfail:The fitting algorithm failed.
>> \!\(\*
>>  RowBox[{\(General::"ivar"\),
>>    ":", "\<\"\\!\\(1\\) is not a valid variable.
>> \\!\\(\\*ButtonBox[\\\"More\
>> ButtonFrame->None, \
>> ButtonData:>\\\"General::ivar\\\"]\\)\"\>"}]\)
>> NonlinearFit::fitfail:The fitting algorithm failed.
>> \!\(\*
>>  RowBox[{\(General::"ivar"\),
>>    ":", "\<\"\\!\\(2\\) is not a valid variable.
>> \\!\\(\\*ButtonBox[\\\"More\
>> ButtonFrame->None, \
>> ButtonData:>\\\"General::ivar\\\"]\\)\"\>"}]\)
>> \!\(\*
>>  RowBox[{\(General::"stop"\),
>>    ":", "\<\"Further output of \\!\\(General :: \\\"ivar\\\"\\) will
>> be \
>> suppressed during this calculation. \
>> \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\",
>> \\\", ButtonFrame->None,
>> ButtonData:>\\\"General::stop\\\"]\\)\"\>"}]\)
>> NonlinearFit::fitfail:The fitting algorithm failed.
>> \!\(\*
>>  RowBox[{\(General::"stop"\),
>>    ":", "\<\"Further output of \\!\\(NonlinearFit ::
>> \\\"fitfail\\\"\\) will \
>> be suppressed during this calculation.
>> \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\
>> ButtonData:>\\\"General::stop\\\"]\\)\"\>"}]\)
>> {NonlinearFit[{1650, 1750,
>>    1860, 2070, 2300, 2560,
>>    3040, 3710, 4450, 5280,
>>    6080}, k, {0},
>>   {theta, k}], NonlinearFit[
>>   {1650, 1750, 1860, 2070,
>>    2300, 2560, 3040, 3710,
>>    4450, 5280, 6080},
>>   E^theta*k, {1},
>>   {theta, k}], NonlinearFit[
>>   {1650, 1750, 1860, 2070,
>>    2300, 2560, 3040, 3710,
>>    4450, 5280, 6080},
>>   E^(2*theta)*k, {2},
>>   {theta, k}], NonlinearFit[
>>   {1650, 1750, 1860, 2070,
>>    2300, 2560, 3040, 3710,
>>    4450, 5280, 6080},
>>   E^(3*theta)*k, {3},
>>   {theta, k}]}
>> {1130.2091592378029,
>>  1315.4644493997696,
>>  1531.0853778619419,
>>  1782.049249124357}
>> {1130.2091592378029,
>>  1315.4644493997696,
>>  1531.0853778619419,
>>  1782.049249124357}
>>
>> So my questions are:
>>
>> 1)Why does "nlr[t]" appear to work in ver 4.2; but return apparently
>> invalid results for zero and one, but correct results for higher
>> values?
>>
>> 2) Why, in ver 4.2, does "Plot" return the (apparently) correct values
>> with "nlr[t]" without the need for "Evaluate"; whereas "Table" does
>> not?
>>
>> 3)  What changed between versions 4.2 and 5?
>>
>
>
>

• Prev by Date: Re: Re: Re: Bug Report - Two numerical values for a same variable
• Next by Date: Re: computing cumulative sum for list
• Previous by thread: Re: Perplexed by the behavior of NonlinearFit in Mathematica ver 4.2 vs 5.1
• Next by thread: Mathematica 2.23 won't run on XP