Jump to content

help with Pseudocode for algorith


tuinebap88

Recommended Posts

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 by tuinebap88
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by alextui
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.