![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2008
Posts: 2
Rep Power: 0
![]() |
calculate distance using values in an array
Hello,
I am a beginner in perl. I am stuck with a problem. I have an array which looks like this 6.324 32.707 50.379 5.197 32.618 46.826 4.020 36.132 46.259 7.131 38.210 45.919 6.719 38.935 42.270 2.986 39.221 41.892 -0.269 37.184 41.565 These are the X, Y and Z coordinates from a pdb file. I want to calculate the distance using these three coordinate values. First i want to know how to assign these values to the array. I have to use this formula to calculate the distance: $dist = sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2); Till now I have written the script like below to obtain the three columns which is shown above. I am stuck. I need help to calculate distance using 'for loop' and do an iterative distance calculation. my exiting code: open(IN, "/Users/anu/out.pl") or die "$!"; while (my $line = <IN>) { chomp($line); my @array = (split (/\s+/, $line))[6, 7, 8]; print "@array\n"; } close(IN); Thank you... |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Jul 2008
Posts: 6
Rep Power: 0
![]() |
Re: calculate distance using values in an array
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2008
Posts: 2
Rep Power: 0
![]() |
Re: calculate distance using values in an array
its fair enough, when u have a question, u post it to different forums where u get different solutions, which will obviously help me learn and approach the problem from different corners thru different ways. Its a pretty good learning process...
![]() |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2008
Posts: 2
Rep Power: 0
![]() |
Re: calculate distance using values in an array
my $dist;
for(my $val;$val <= $#array; $val ++) { $dist = sqrt( ( $array[$i][0][0] - $array[(1+$i)][0][0] )**(2+($array[0][$i][0] - $array[0][(1+$i)])**... Something like this not the ellipses where i figure you can complete from their, i maybe wrong with my for statement however, the 2nd part, I dont have alot of experience with multidimensional arrays. maybe we could count how many lines of values were taken in and us $i < $lines also, I'm not good with math so my parenthesis my not be correct. simple tweaking should suffice though. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assigning Values into Random Index's in Array | csrocker101 | C# | 9 | Mar 20th, 2008 3:46 AM |
| changing size of an array | Eric the Red | Java | 3 | Apr 3rd, 2006 8:19 PM |
| Combining Values in an array | bigmitch | C++ | 4 | Feb 10th, 2006 7:29 AM |
| need help passing array values | bjbcartmen | C | 9 | Dec 20th, 2005 10:08 AM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 2:36 AM |