Re: Equivalent functions generate different plots
- To: mathgroup at smc.vnet.net
- Subject: [mg26172] Re: [mg26112] Equivalent functions generate different plots
- From: BobHanlon at aol.com
- Date: Thu, 30 Nov 2000 01:04:13 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
data = {{0, 79.6}, {0.2, 79.2}, {0.4, 77.1}, {0.6, 73.7}, {0.8, 69.1}, {1., 63.2}}; f[t_] := Evaluate[Fit[data, {1, t, t^2}, t]]; g[t_] := Fit[data, {1, t, t^2}, t]; f[t] == g[t] True Plot[{f[t], g[t]}, {t, 0, 2.2}, PlotStyle -> {{RGBColor[0, 0, 1], AbsoluteDashing[{5, 5}], AbsoluteThickness[2]}, {RGBColor[1, 0, 0], AbsoluteDashing[{5, 15}], AbsoluteThickness[2]}}]; Attributes[Plot] {HoldAll, Protected} Since Plot has attribute HoldAll, the iterator t is set before g[t] is evaluated. This results in g[t] being improperly evaluated. You must Evaluate the functions within Plot. Plot[Evaluate[{f[t], g[t]}], {t, 0, 2.2}, PlotStyle -> {{RGBColor[0, 0, 1], AbsoluteDashing[{5, 5}], AbsoluteThickness[2]}, {RGBColor[1, 0, 0], AbsoluteDashing[{5, 15}], AbsoluteThickness[2]}}]; Bob Hanlon In a message dated 11/28/00 3:15:10 AM, gerbual at col2.telecom.com.co writes: >With: > >In[1]:= >data = {{0, 79.6}, {0.2, 79.2}, {0.4, 77.1}, {0.6, 73.7}, {0.8, 69.1}, > >{1., 63.2}}; > >I can to get its cuadratic regression function: > >In[2]:= >Fit[data, {1, t, t^2}, t] > >Out[2]= >79.68214285714285` + 0.21249999999984936` t - 16.741071428571246` t^2 > >Then, I can define the regression function in two different, but >equivalent ways: > >First: copying and pasting the last output: > >In[3]:= >f[t_] := > 79.68214285714285`+ 0.21249999999984936` t - 16.741071428571246 t^2 > >Second: using directly the *Fit* function in the right hand: > >In[4]:= >g[t_] := Fit[data, {1, t, t^2}, t] > >In this conditions: > >In[5]:= >f[t] == g[t] > >Out[5]= >True > >However: > >In[6]:= >Plot[{f[t], g[t]}, {t, 0, 2.2}] > >Out[6]= > >(GRAPHICS ...!!!) > >genere two different plots (a straight line and a curve). The curve is > >well, but the straight line not. I DON'T UNDERSTAND. Can somebody >explain to me this inconsistency? >