Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #1692

Defining multiple similar functions, and fitting them, using a for loop

X-Received by 10.224.189.78 with SMTP id dd14mr2189199qab.0.1363282450521; Thu, 14 Mar 2013 10:34:10 -0700 (PDT)
X-Received by 10.49.105.163 with SMTP id gn3mr268417qeb.13.1363282450488; Thu, 14 Mar 2013 10:34:10 -0700 (PDT)
Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!t2no2806088qal.0!news-out.google.com!k8ni188qas.0!nntp.google.com!dd2no718218qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.graphics.apps.gnuplot
Date Thu, 14 Mar 2013 10:34:10 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=128.205.165.209; posting-account=32MjRQoAAAA5ZMyB6rR1GNASn8thjwWI
NNTP-Posting-Host 128.205.165.209
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <52d92c72-a809-490f-86e9-c577132ffa44@googlegroups.com> (permalink)
Subject Defining multiple similar functions, and fitting them, using a for loop
From Thomas Grant <tomer485@gmail.com>
Injection-Date Thu, 14 Mar 2013 17:34:10 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Lines 50
Xref csiph.com comp.graphics.apps.gnuplot:1692

Show key headers only | View raw


Dear all,

I am trying to use gnuplot to iterate through a list of data files and fit the data in them with a simple linear regression.  Then I would like to plot all the data points and the accompanying fits on the same graph.  From the help it seems like the for loop iteration only works for plotting commands, and not for fit.

First, I would like to fit all the data files to a function:

f1(x)=m1*x+b1
f2(x)=m2*x+b2
etc...

then I'd like to fit them:

fit f1(x) 'datafile_1.dat' via m1,b1
etc....

then I'd like to plot the data files, which I can do with a for loop:

plot for [i=1:8] 'datafile_'.i.'.dat'  

however, I'd also like to plot the fits, which doesn't seem to work with a for loop.  I've tried the following (after individually defining f1(x), f2(x), etc...):

plot for [i=1:8] fi(x)
plot for [i=1:8] f.i.(x)
plot for [i=1:8] j=i fj(x)
plot for [i=1:8] j=i f.j.(x)
plot for [i=1:8] j=i "f".j."(x)"

and none of these seem to work.  It occurs to me it may be that gnuplot doesn't seem to support the idea of defining functions with a variable, even though it would allow something such as:

plot for [i=1:8] j=i sin(i*x)

which would plot eight functions, sin(x), sin(2x), etc...

If anyone has any ideas on fitting multiple functions, I'd love to hear it.  Or if anyone has any ideas on defining/plotting functions with variable names, I'd also love to hear it.

If possible I would like to avoid scripting, since I would like to be able to make edits interactively in gnuplot, rather than editing a script, running it, looking at the output, re-editing the script, running it, etc... 

Thanks for your suggestions,
Tom

Back to comp.graphics.apps.gnuplot | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Defining multiple similar functions, and fitting them, using a for loop Thomas Grant <tomer485@gmail.com> - 2013-03-14 10:34 -0700
  Re: Defining multiple similar functions, and fitting them, using a for loop Karl <mail.kfr@gmx.net> - 2013-03-15 08:49 +0100
    Re: Defining multiple similar functions, and fitting them, using a for loop Karl <mail.kfr@gmx.net> - 2013-03-15 08:59 +0100
    Re: Defining multiple similar functions, and fitting them, using a for loop Karl <mail.kfr@gmx.net> - 2013-03-15 14:45 +0100
    Re: Defining multiple similar functions, and fitting them, using a for loop Karl <mail.kfr@gmx.net> - 2013-03-15 16:50 +0100
      Re: Defining multiple similar functions, and fitting them, using a for loop sfeam <sfeam@users.sourceforge.net> - 2013-03-15 11:52 -0700
  Re: Defining multiple similar functions, and fitting them, using a for loop kress.florian@gmail.com - 2013-05-23 13:03 -0700
    Re: Defining multiple similar functions, and fitting them, using a for loop sfeam <sfeam@users.sourceforge.net> - 2013-05-23 15:34 -0700

csiph-web