compiler-errors - Gnuplot : fitting different curves

标签 compiler-errors syntax-error gnuplot curve-fitting data-fitting

我试图在gnuplot中容纳一些数据。数据是不同的曲线。我有三个.gnp文件:一个用于数学过程,一个用于调用要分析的文件,另一个必须在gnuplot中启动。

我得到的是这个错误,但我不知道如何解决。

gnuplot> load '0-one_fit.gnp'

gnuplot> id = $0
           ^

"0-one_fit.gnp" line 5: column() called from invalid context



该文件应存储从0到变量ID的序列号。序列号通过命令调用从loop.gnp外部传递到此脚本。

该文件说:
    id = $0
    filename = sprintf("FeCoBSiNbCu%04d.chi",id)
    fit [26:35.6] f110(x) filename u 1:2 via x110,A110,w110,a0,a1
    fit [42.3:45.1] f200(x) filename u 1:2 via x200,A200,w200,b0,b1
    fit [48:56.1] f23(x) filename u 1:2 via x2,A2,w2,x211,A211,w211,c0,c1


    entry1 = sprintf("%d\t%.3f\t%.3f\t%.1f\t%.1f\t%.3f\t%.3f\t",id,x110,x110_err,A110,A110_err,w110,w110_err)
    entry2 = sprintf("%.3f\t%.3f\t%.1f\t%.1f\t%.3f\t%.3f\t",x200,x200_err,A200,A200_err,w200,w200_err)
    entry3 = sprintf("%.3f\t%.3f\t%.1f\t%.1f\t%.3f\t%.3f\t",x2,x2_err,A2,A2_err,w2,w2_err)
    entry4 = sprintf("%.3f\t%.3f\t%.1f\t%.1f\t%.3f\t%.3f",x211,x211_err,A211,A211_err,w211,w211_err)
print entry1, entry2, entry3, entry4

更新:
我使用id=ARG1更改了文件,但是现在它给了我另一个错误
gnuplot> call '0-one_fit.gnp' 0
     "0-one_fit.gnp" line 8: f_sprintf: attempt to print string value with numeric format

如果我现在用int(id)更改,它说:
load '0-one_fit.gnp'
     "0-one_fit.gnp" line 8: Non-numeric string found where a numeric expression was expected

更新
我尝试首先运行名为0-in-situ.gnp的文件,其中包含用于峰拟合的函数:
#### First peak: (110)

bg110(x) = a0 + a1*x

k110(x) = (x-x110)/w110

Gauss110(x) = A110*exp(-log(2)*k110(x)**2)
Cauchy110(x) = A110/(1 + k110(x)**2)

pV110(x) = alpha*Gauss110(x) + (1-alpha)*Cauchy110(x)

f110(x) = pV110(x) + bg110(x)


#### Second peak: (200)

bg200(x) = b0 + b1*x

k200(x) = (x-x200)/w200

Gauss200(x) = A200*exp(-log(2)*k200(x)**2)
Cauchy200(x) = A200/(1 + k200(x)**2)

pV200(x) = beta*Gauss200(x) + (1-beta)*Cauchy200(x)

f200(x) = pV200(x) + bg200(x)


#### Third peak & deconvolution (Q2 & 211):

bg(x) = c0 + c1*x

k2(x) = (x-x2)/w2
k211(x) = (x-x211)/w211

Gauss2(x) = A2*exp(-log(2)*k2(x)**2)
Cauchy2(x) = A2/(1 + k2(x)**2)
pV2(x) = gamma*Gauss2(x) + (1-gamma)*Cauchy2(x)

Gauss211(x) = A211*exp(-log(2)*k211(x)**2)
Cauchy211(x) = A211/(1 + k211(x)**2)
pV211(x) = delta*Gauss211(x) + (1-delta)*Cauchy211(x)

f23(x) = pV2(x) + pV211(x) + bg(x)

alpha = 0
beta = 0
gamma = 1
delta = 0

A110 = 15574
x110 = 31.1
w110 = 2.4 
a0 = 1760 
a1 = 6

A200 = 4153
x200 = 52.2
w200 = 3
b0 = 1500
b1 = 15

A2 = 1800
x2 = 51.6
w2 = 3
A211 = 1897
x211 = 76.6
w211 = 0.3
c0 = 1830
c1 = -2

#### Loop through all XRD patterns: 
load "0-loop.gnp"

程序运行了,但是当我打开应包含数据的文件.dat时,显然它不会分析所有曲线,而只会分析第一个曲线。这是下面循环的问题吗?
call "0-one_fit.gnp" 447
call "0-one_fit.gnp" 448
call "0-one_fit.gnp" 449
call "0-one_fit.gnp" 450
call "0-one_fit.gnp" 451
call "0-one_fit.gnp" 452

最佳答案

您可以在绘图命令中使用$0column(0)或在绘图命令中使用的函数。在其他地方,我猜这是“无效的上下文”。
检查以下示例:

还要检查help usinghelp columnhelp pseudocolumns

reset session

$Data <<EOD
11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
41 42 43 44 45
EOD

# id = $0            # does not work, invalid context
# id = column(0)     # does not work, invalid context
id(n) = column(n)    # within a function, works

plot $Data u           0:1 w lp    # works
plot $Data u        ($0):1 w lp    # works
plot $Data u (column(0)):1 w lp    # works
plot $Data u     (id(0)):1 w lp    # works

编辑:

我想,我误会了你的问题。我以为您想将列值分配给变量。

如果要将参数传递给gnuplot例程,则可以对带有参数的gnuplot文件call(而不是load)。
call '0-one_fit.gnp' 123
0-one_fit.gnp中,您可以通过id = ARG1访问此值。
在早期的gnuplot版本(“旧样式”)中,这是id=$0

检查help callhelp call old-style(gnuplot 5.2)

关于compiler-errors - Gnuplot : fitting different curves,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58199317/

相关文章:

ios - 参数类型 'customClass.Type' 不符合预期类型 'NSItemProviderWriting'

Java基本编译错误

performance - 将大数据集绘制为动画时 gnuplot 速度较慢

php - PHP解析/语法错误;以及如何解决它们

file - 为什么 Gnuplot 中的 'set table' 选项会重写最后一行的第一个条目?

gnuplot - 如何在 gnuplot 中对整个列求和?

compiler-errors - 编程新手,无法让Visual Studio 2013打开包含文件

c++ - 琐碎的 “Not declared in this scope”错误

php - 常量表达式包含无效操作

javascript - TypeScript 编译后 : Uncaught SyntaxError: Unexpected token {