By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,778 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,778 IT Pros & Developers. It's quick & easy.

Python program to calculate an expression (equation) from the values of second column

P: 4
I have values as:

0.263 0

0.265 0

0.267 0

0.269 0.0001

0.271 0.0003

0.273 0.0006

0.275 0.0011

0.277 0.0021

0.279 0.0029

0.281 0.0046

0.283 0.0072

0.285 0.0113

And i want to calculate the expression ie., PMF(W_r)= k_b T ln g(r). Where the g(r) are the values of the second column.

Here is the code that i have tried:
Expand|Select|Wrap|Line Numbers
  1. import numpy as np
  2. #import panda as pd
  3. import scipy.constants as sc
  4. #from astropy import constants as const
  5. import matplotlib.pyplot as plt
  6. import math
  7. A=open('rdf_CaOw.dat','r')
  8. B=open('pmf.dat','w')
  9. for column in A:
  10.     c=column.strip().split()
  11.     B.write(column[6:11]+'\n')
  12. B.close()
  13. A.close()
  14.  
  15. C=open('pmf.dat', 'r')
  16. D=open('pmf1.dat','w')
  17. for line in C:
  18.     W = (- float(sc.Boltzmann * 298 * float (math.log (C))))
  19.     print (W)
  20.  
1) Any suggestions on this.

2) Can i directly take the second column and insert/put in the equation to calculate..?? How can i do this? Since here i am writing the second column to one output file and from that output file again i am putting the equation.

Any suggestions are highly appreciated.

Thank you.
May 28 '18 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
Print "c" in the code after the for. I think you want c[1], but print it and see for yourself. Also you may have to typecast to a float https://pythonspot.com/datatype-casting/
May 28 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.