SourceForge has been redesigned. Learn more.
Close

undefined variable

Fabian
2014-06-24
2014-07-02
  • Fabian

    Fabian - 2014-06-24

    Hallo

    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.

    "
    a_0=1.0
    a_1=1.0
    c_0=1.0
    b_0=1.0
    b_1=1.0
    c_1=1.0
    set xrange [0:60]
    set yrange [0:60]
    f(x,y)=(x^2)(a_0+a_1(y-c_0)^2)+b_0+b_1*(y-c_1)^4
    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

    load 'input.txt'
    "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.

    Yours scincerely
    Fabian

     
  • Hans-Bernhard Broeker

    Which version of gnuplot is it you're using? Platform?

    f(x,y)=(x**2)*(a_0+a_1*(y-c_0)**2)+b_0+b_1*(y-c_1)**4
    

    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.

     
  • Fabian

    Fabian - 2014-06-26

    Hallo

    I'm using gnuplot 4.6.

     
  • Hans-Bernhard Broeker

    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

     
  • Fabian

    Fabian - 2014-06-29

    Tank you for your help.

    Now I have another problem. These nine point are stored in a file.

    e.g.

    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?

    Like
    A=1,989
    B=2.025
    C=1.977
    .
    .
    .

     
  • Fabian

    Fabian - 2014-07-02

    Can anyone help me?

     
  • shadowwalkersb

    shadowwalkersb - 2014-07-02

    Put this in a script.

    test.gnu:

    z=""

    populate_z(x)=(z=sprintf("%s %f",z,x), x)

    pl 'test.dat' u 1:(populate_z($3))
    EOF

    It is attached, too. In gnuplot call this script with

    load 'test.gnu'

    Then, all your variables in the third column will be available in variable z. You can access them with

    A=word(z,1)
    B=word(z,2)
    C=word(z,3)
    ....
    G=word(z,9)

    If you need them as numbers, following should do the trick (I haven't tested it)

    A=word(z,1)1
    B=word(z,2)
    1
    C=word(z,3)1
    ....
    G=word(z,9)
    1

    If you don't want to plot, you can replace 'plot .....' with
    'stats ....' (Available in 4.6)

     
    Last edit: shadowwalkersb 2014-07-02

Log in to post a comment.