MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ListPlotFit

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17191] Re: ListPlotFit
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Tue, 20 Apr 1999 01:21:02 -0400
  • References: <7fbnsj$957@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Marrten,

ListPlotFit[l_, start_:1, stop_] :=
Module[
{lp, fie, fiep},
lp = ListPlot[l, DisplayFunction -> Identity, PlotStyle ->
PointSize[0.015], PlotRange -> All];
fie = Fit[l[[Table[j, {j, start, stop}]]], {1, x}, x];
fiep = Plot[fie, {x, 1, Length[l]}, DisplayFunction -> Identity];
Show[lp, fiep, DisplayFunction -> $DisplayFunction]
]

ListPlotFit[l_, start_:1]:=
ListPlotFit[l, start, Length[l]]

Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


<Maarten.vanderBurgt at icos.be> wrote in message
news:7fbnsj$957 at smc.vnet.net...
> Hello,
>
>
> With the function ListPlotFit below I combine ListPlot with Fit and Plot
in
> order to show the data from list l together with the straight line fitted
> through a part of the data points from list l. The list l  is of form
> {{x1,y1},{x2,y2}, ...}.
>
> The part of the data points I want to fit a line through is determined by
> start and stop. The default value for the optional argument stop is 10.
> This is not really what I want: I want the default value for stop to be
> stop = Length[l]. How can I achieve this?
>
> I tried ListPlotFit[l_, start_:1, stop_:Hold[Lenght[l]] := Module[{},stop
=
> ReleaseHold[stop];...], but this did not work (I get an error: "Hold is
> Protected..."). I think I need Hold or something of the sort otherwise
> Lenght[l] gets evaluated to 1 immediately.
>
> I guess I can phrase my question more general: how do I define a function
F
> with an optional argument v which has as default value a function g of a
> non-optional argument u (i.e. F[u_, v_:g[u]])?
>
>
> In[1]:= ListPlotFit[l_, start_:1, stop_:10] :=
>   Module[
>    {lp, fie, fiep},
>    lp = ListPlot[l, DisplayFunction -> Identity, PlotStyle ->
> PointSize[0.015], PlotRange -> All];
>    fie = Fit[l[[Table[j, {j, start, stop}]]], {1, x}, x];
>    fiep = Plot[fie, {x, 1, Length[l]}, DisplayFunction -> Identity];
>    Show[lp, fiep, DisplayFunction -> $DisplayFunction]
>   ]
>
> In[2]:= dat= Table[{i,3*i^2+5+2*(Random[]-0.5)},{i,1,15}];
> In[3]:= ListPlotFit[dat, 2, 12];
>
>
> Any help is greatly appreciated
> thanks
>
> Maarten
>
>
> _______________________________________________________________
>
> Maarten van der Burgt
> R&D Department
>
> ICOS Vision Systems
> Esperantolaan 9
> B-3001 Leuven, Belgium
> tel. + 32 16 398220; direct + 32 16 398316; fax. + 32 16 400067
> e-mail: maarten.vanderburgt at icos.be
> _______________________________________________________________
>
>
>
>
>



  • Prev by Date: Ratio Polynomial Fit
  • Next by Date: MATHEMATICA GUIDEBOOK
  • Previous by thread: ListPlotFit
  • Next by thread: Re: ListPlotFit