Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #1854
| From | sfeam <sfeam@users.sourceforge.net> |
|---|---|
| Newsgroups | comp.graphics.apps.gnuplot |
| Subject | Re: Defining multiple similar functions, and fitting them, using a for loop |
| Followup-To | comp.graphics.apps.gnuplot |
| Date | 2013-05-23 15:34 -0700 |
| Organization | gnuplot development team |
| Message-ID | <knm5a5$oi0$1@dont-email.me> (permalink) |
| References | <52d92c72-a809-490f-86e9-c577132ffa44@googlegroups.com> <eee78761-c914-4658-86b1-c10ee0fa56e8@googlegroups.com> |
Followups directed to: comp.graphics.apps.gnuplot
kress.florian@gmail.com wrote: > On Thursday, March 14, 2013 6:34:10 PM UTC+1, Thomas Grant wrote: >> Dear all, >> >> 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. I don't have an answer for handling an unbounded number of previously unknown functions, but for some reasonable number, say 10 or so, you can create a little pre-definition script that maps fi(x) onto g(i,x) g(i,x) = \ i == 1 ? f1(x) : \ i == 2 ? f2(x) : \ i == 3 ? f3(x) : \ i == 4 ? f4(x) : \ i == 5 ? f5(x) : \ i == 6 ? f6(x) : \ i == 7 ? f7(x) : \ i == 8 ? f8(x) : \ i == 9 ? f9(x) : \ i == 10 ? f10(x) : \ NaN Now your plot command is plot for [i=1:8] g(i,x) Ethan
Back to comp.graphics.apps.gnuplot | Previous | Next — Previous in thread | Find similar
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