I want to evaluate the Birch-Murnaghan Equation of State (BM-EOS) for different volumes.
I tried declaring a 1D array A in which every element would be the answer of BM-EOS for different volumes.

B0P = 4; B0 = 30
V0 = 36; E0 = -535; R4  = -535
array A[400]
do for [i=1:400] {
A[i] = E0+(9/8*B0*V0)*((V0/((((i/100)**3)/100)**3))**(2/3)-1)**2\
         + 9/16*B0*(B0P-4)*V0*((V0/((i/100)**3))**(2/3)-1)**3\
         + R4*((V0/((i/100)**3))**(2/3)-1)**4

I am getting error as undefined value. Can anyone please tell what is wrong in this Gnuplot code?
Later I will use stats command on A to find the minimum value. Also, is there any other better way to find out minima of a fit function in Gnuplot? This answer did not help much: Gnuplot: How can I determine the maxima of a fit function in gnuplot?


You must put a dot in all the numbers which are supposed to be floats, so as to be correct while doing division. In gnuplot

2/3 = 0


2.0/3.0 = 0.66666..7

In your example, you are suffering from division by zero, but gnuplot does not give good error message.

Here is corrected version which runs without any error

B0P = 4.0; B0 = 30.0
V0 = 36.0; E0 = -535.0; R4  = -535.0
array A[400]
do for [i=1:400] {
   A[i] = E0+(9.0/8.0*B0*V0)*((V0/((((i/100.0)**3)/100.0)**3))**(2.0/3.0)-1.0)**2\
     + 9.0/16.0*B0*(B0P-4.0)*V0*((V0/((i/100.0)**3))**(2.0/3.0)-1.0)**3\
     + R4*((V0/((i/100.0)**3))**(2.0/3.0)-1.0)**4

I use Gnuplot daily and like it a lot for plotting. But it is not really designed for computations. Why dont you use python for this ?

  • $\begingroup$ I can use Python. Since I already had the code written for Gnuplot hence thought of modifying it. Now, I'll have to start from scratch in Python. $\endgroup$
    – Sufyan
    Aug 13 '20 at 15:45
  • $\begingroup$ Thanks. Your suggestion did clear that error message. A new error has come up: "Column number or datablock line expected" pointing towards "9.0/8.0" Looks like I should python only for this. $\endgroup$
    – Sufyan
    Aug 13 '20 at 15:52
  • $\begingroup$ It works if you add .0 as I did in my updated answer. If this works for you, please accept the answer so we can close this thread. $\endgroup$
    – cfdlab
    Aug 14 '20 at 5:48
  • $\begingroup$ Thanks. It worked. $\endgroup$
    – Sufyan
    Aug 14 '20 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.