It seems individual array values do not work the same way in gnuplot as normal variables.
I have tried the following code given below.
# Following code doesn't work.
reset
# Parameters and fitting curve
n = 3
array p[n]
p[1] = 1.3 ; p[2] = 0.2 ; p[3] = 0.7
f(x) = p[1] * sin( p[2] + p[3] * x )
set fit
fit f(x) 'datafile.txt' using 1:2 via p[1], p[2], p[3]
unset fit
I get the following error: line 11: unknown type in real()
Note that if I change the arrays p[1], p[2], p[3]
, to a, b, c
the code works.
# Following works.
reset
a = 1.3 ; b = 0.2 ; c = 0.7
f(x) = a * sin( b + c * x )
set fit
fit f(x) 'datafile.txt' using 1:2 via a, b, c
unset fit
Partial data is given below (should be saved as 'datafile.txt') for completeness:
# x y
0 0.0222457
0.1 0.113168
0.2 0.252268
0.3 0.378091
0.4 0.397219
0.5 0.577536
0.6 0.621418
0.7 0.695817
0.8 0.741057
0.9 0.849566
1 0.864276
So my question is:
- Is my assumption correct that gnuplot arrays do not work the same way as normal variables?
- Is there a way to make the arrays behave in the same manner as normal variables?