Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
700 views
in Technique[技术] by (71.8m points)

awk - bash: calculation of the RMSD from the dataset

I have a my_file.xvg contained 240 lines with the numbers arranged in the following format:

    5.4
    5.1
    5.2
    5.4
    5.4
    4.9
    5.0
    5.2
....
    4.9

Using awk I have already calculated the mean value of these data and store it as a "mean" variable in the bash script:

mean=$(awk '{sum+=$1}END{printf "%.1f", sum/NR}' my_file.xvg)

How could I calculate RMSD of these numbers (to determine error of the mean for instance) and store it as the another variable?

question from:https://stackoverflow.com/questions/66047971/bash-calculation-of-the-rmsd-from-the-dataset

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Once the value of the mean is saved in the variable a very similar approach can be used for the RMSD. As you seem to prefer awk, see the following:

rmsd=$(awk -v mean=$mean '{++n;sum+=($NF-mean)^2} END{if(n) print sqrt(sum/n)}' my_file.xvg)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...