tuinebap88 Posted October 16, 2011 Posted October 16, 2011 (edited) Hi all, I am a biology student, and didn't have any experience with computer science; very struggle with this homework for my computer class; Can someone please help me, give me a hint how to do it? Thank. Here is the question: Write a pseudocode for the algorithm There is a term in an energy function that is a function of the distance between all pairs of atom in a structure. a. Find the distance between two atoms. b. Sum the function (1./distance) overall all unique pair of atoms. Exclude summing atom with themselves since that would be unbounded. Edited October 16, 2011 by tuinebap88
timo Posted October 17, 2011 Posted October 17, 2011 You should probably start by assuming that there is some kind of data structure (e.g. an array of 3D vectors or an array or length-3 arrays) that provides the coordinates of the atoms. From that on I would sketch a function // calculate the distance between the atoms with numbers a1 and a2. double-valued function distance(int a1, int a2) // pseudocode comes here and a function // calculate the sum of 1/distance over all pairs of atoms. double-valued function sum_of_one_over_distance // pseudocode comes here
alextui Posted October 17, 2011 Posted October 17, 2011 (edited) Are you expect a brute force algorithm or an optimized one? If you want an optimized one, we need to know more detail/ property of those atom or structure. here is the brute force one: Assuming all atoms is in array atom[x] i=0; sum=0; for each atom[i] i++; j=0; for each atom[j] if(i==j) next; sum=sum+calcFunction(atom[i]+atom[j]); end for end for Edited October 17, 2011 by alextui
timo Posted October 17, 2011 Posted October 17, 2011 Hi alextui, and welcome to sfn (in case no one welcomed you here, yet). There is a general consensus here that homework help is not supposed to give the answers to questions but to help the people solve their problems themselves, so it would be nice if you tried to stick to that. You are of course right that tuinebab88 should give a few more details. Especially on what his ideas are and where and why he got stuck.
Faz Posted October 30, 2011 Posted October 30, 2011 Hi. You'll want to use Pythagorus' theorum to calculate the 3d distance between any 2 atoms. For each distance, put it through the function said (1/distance) then just sum them all together to give the result.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now