I have the following problem.
I have nine points (x,y,z) and I want to fit a surface through them. I have the forumla for it.
So far I've tried:
I have a .txt file with the nine points. Then I creat a input file with the following content.
set xrange [0:60]
set yrange [0:60]
fit 'test.dat' f(x,y) via a_0,a_1,b_0,b_1,c_0,c_1
splot f(x,y), 'test.dat' w p
(I know ^ is wrong. But with ** it is displayed uncorrectly)
If I want to plot it it says
"input.txt", line 10: undefined variable: x
I also tried it with the variables u and v.
What am I doing wrong?
Thank you for you help.
Which version of gnuplot is it you're using? Platform?
Your 'fit' command doesn't actually indicate that you're trying to do a 2-variable fit. Depending on the version of gnuplot you have, you'll have to add a 'using' specification to tell 'fit' about this.
I'm using gnuplot 4.6.
In that case you'll have to add a "using" specification to your command
fit 'test.dat' f(x,y) using 1:2:3:(1.0) via a_0,a_1,b_0,b_1,c_0,c_1
Tank you for your help.
Now I have another problem. These nine point are stored in a file.
x y z
0 0 1.989
0 3 2.025
0 6 1.977
3 0 1.955
3 3 2.006
3 6 1.949
6 0 1.841
6 3 1.921
6 6 1.897
Is it possible to assign the z-value from this file to a variable?
Can anyone help me?
Put this in a script.
populate_z(x)=(z=sprintf("%s %f",z,x), x)
pl 'test.dat' u 1:(populate_z($3))
It is attached, too. In gnuplot call this script with
Then, all your variables in the third column will be available in variable z. You can access them with
If you need them as numbers, following should do the trick (I haven't tested it)
If you don't want to plot, you can replace 'plot .....' with
'stats ....' (Available in 4.6)
Log in to post a comment.