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


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

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

Newsgroups comp.graphics.apps.gnuplot
Date 2013-05-23 13:03 -0700
References <52d92c72-a809-490f-86e9-c577132ffa44@googlegroups.com>
Message-ID <eee78761-c914-4658-86b1-c10ee0fa56e8@googlegroups.com> (permalink)
Subject Re: Defining multiple similar functions, and fitting them, using a for loop
From kress.florian@gmail.com

Show all headers | View raw


On Thursday, March 14, 2013 6:34:10 PM UTC+1, Thomas Grant wrote:
> 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

I am trying to do the same, but can't get it.
could you please post your running code?

thanks florian

Back to comp.graphics.apps.gnuplot | Previous | NextPrevious in thread | Next in thread | Find similar


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