使用gnuplot将函数与多个数据集拟合 [英] fitting a function with multiple data sets using gnuplot

查看:121
本文介绍了使用gnuplot将函数与多个数据集拟合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用许多数据集来拟合一个函数。例如,每次获得一对数据列(x,y)时,我都会多次重现经验。我将所有这些列放在名为 data.txt的文件中:



第一次体验:x =第1列,y =第2列



第二次体验:x =第5列,y =第6列


第二次体验:x =第3列,y =第4列



第三次体验:x =第5列,y =第6列



...



现在我希望对这些数据集拟合函数y = f(x)。我不知道Gnuplot可以做到吗?如果可能,请您帮我纠正以下命令?

  fit f(x) data.txt u 1:2:(0.25), data.txt u 3:4:(0.25), data.txt u 5:6:(0.25)通过a,b 


解决方案

您可以处理数据,以使第1、3和5列都成为同一列1,而第2、4和6列都成为相同列第2栏。使用 awk 很容易,您可以在 gnuplot 之外进行操作:

  awk'{print $ 1,$ 2} {print $ 3,$ 4} {print $ 5,$ 6}'data.txt> data2.txt 

,然后将其放入 gnuplot

  f(x)= a * x + b 
fit f(x) data2.txt u 1:2:(0.25)通过a,b

或者您也可以完全在 gnuplot 没有任何中间文件:

  f(x)= a * x + b 
fit f(x)


I would like to fit a function using many data sets. For example, I reproduce an experience many times, each time I obtain a pair of data column (x,y). I put all these column in a file named 'data.txt' :

first experience : x = column 1, y = column 2

second experience : x = column 3, y = column 4

third experience : x = column 5, y = column 6

...

Now I wish to fit a function y = f(x) for these data sets. I do not know if Gnuplot can do that ? If it is possible, could you please help me to correct the following command ? This one does not work.

fit f(x) "data.txt" u 1:2:(0.25), "data.txt" u 3:4:(0.25), "data.txt" u 5:6:(0.25) via a, b

解决方案

You can process your data so that columns 1, 3 and 5 all become the same column 1, and columns 2, 4 and 6 all become the same column 2. It's easy with awk, you can do it outside gnuplot:

awk '{print $1, $2} {print $3, $4} {print $5, $6}' data.txt > data2.txt

and then fit it within gnuplot:

f(x)=a*x+b
fit f(x) "data2.txt" u 1:2:(0.25) via a,b

Or you can do it completely within gnuplot without any intermediate file:

f(x)=a*x+b
fit f(x) "< awk '{print $1, $2} {print $3, $4} {print $5, $6}' data.txt" u 1:2:(0.25) via a,b

这篇关于使用gnuplot将函数与多个数据集拟合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆