       Re: Equivalent functions generate different plots

• To: mathgroup at smc.vnet.net
• Subject: [mg26185] Re: [mg26112] Equivalent functions generate different plots
• From: Tomas Garza <tgarza01 at prodigy.net.mx>
• Date: Thu, 30 Nov 2000 01:04:24 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Hola German,

There is no lack of consistency. You see, if you copy the output of
Fit[] as the definiton of f[t_] you are using an explicit function of t.
However, if you define g[t_] as in your In you obtain an error
message:

In:=
g[t_] = Fit[data, {1, t, t^2}, t]
Set::"write":    "Tag Plus in (79.68214285714285`+<< 20>> t
-16.741071428571246` t^2)[t_] is Protected."
Out=
79.68214285714285` + 0.21249999999984936`t - 16.741071428571246`t^2

the reason being that g itself is already a function of t, and it is as
if you were writing g[t][t_]. If instead you take

In:=
g = Fit[data, {1, t, t^2}, t]
Out=
79.68214285714285`+
0.21249999999984936` t - 16.741071428571246` t^2

you can plot both g and f[t]:

In:=
Plot[{f[t], g}, {t, 0, 2.2}]

and you mustn't write explicitly the argument of g. It is already there.

Now, if you wanted to know the value of the fitted function g for a
given value of t, say t = a, then you can use

In:=
g /. t -> a
Out=
79.68214285714285`+
0.21249999999984936` a - 16.741071428571246`a^2

and then you could define, e.g.

In:=
h[x_] := g /. t -> x

so that you may now plot h[x] with its argument explicitly written:

In:=
Plot[h[x], {x, 0, 2.2}]

A bit tricky, though, but it would have been helpful if you had looked
at the FullForm of Fit[] from the very beginning..

Tomas Garza
Mexico City

"GERMAN" <gerbual at col2.telecom.com.co> wrote:

> With:
>
> In:=
> 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:=
> Fit[data, {1, t, t^2}, t]
>
> Out=
> 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:=
> f[t_] :=
>     79.68214285714285`+ 0.21249999999984936` t - 16.741071428571246
t^2
>
> Second: using directly the *Fit* function in the right hand:
>
> In:=
> g[t_] := Fit[data, {1, t, t^2}, t]
>
> In this conditions:
>
> In:=
> f[t] == g[t]
>
> Out=
> True
>
> However:
>
> In:=
> Plot[{f[t], g[t]}, {t, 0, 2.2}]
>
> Out=
>
> (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?

```

• Prev by Date: Re: Symbolic complex conjugation
• Next by Date: Re: How to plot field lines of conformal mapping
• Previous by thread: Re: Equivalent functions generate different plots