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> Subject: Defining multiple similar functions, and fitting them, using a for loop From: Thomas Grant 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 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 plo= t all the data points and the accompanying fits on the same graph. From th= e help it seems like the for loop iteration only works for plotting command= s, and not for fit. First, I would like to fit all the data files to a function: f1(x)=3Dm1*x+b1 f2(x)=3Dm2*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=3D1:8] 'datafile_'.i.'.dat' =20 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=3D1:8] fi(x) plot for [i=3D1:8] f.i.(x) plot for [i=3D1:8] j=3Di fj(x) plot for [i=3D1:8] j=3Di f.j.(x) plot for [i=3D1:8] j=3Di "f".j."(x)" and none of these seem to work. It occurs to me it may be that gnuplot doe= sn't seem to support the idea of defining functions with a variable, even t= hough it would allow something such as: plot for [i=3D1:8] j=3Di 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 n= ames, 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, runni= ng it, looking at the output, re-editing the script, running it, etc...=20 Thanks for your suggestions, Tom