MathGroup Archive 1999

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

Search the Archive

ListPlotFit

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17147] ListPlotFit
  • From: Maarten.vanderBurgt at icos.be
  • Date: Sun, 18 Apr 1999 00:59:38 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

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: Re: ListPlotFit
  • Next by Date: Re: Step functions
  • Previous by thread: Re: ListPlotFit
  • Next by thread: Re: ListPlotFit