Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 1st, 2008, 4:51 AM   #1
annie_singh
Newbie
 
Join Date: Oct 2008
Posts: 2
Rep Power: 0 annie_singh is on a distinguished road
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...
annie_singh is offline   Reply With Quote
Old Oct 2nd, 2008, 2:52 AM   #2
KevinADC
Newbie
 
Join Date: Jul 2008
Posts: 6
Rep Power: 0 KevinADC is on a distinguished road
Re: calculate distance using values in an array

Thats not nice.......

http://www.perlguru.com/gforum.cgi?post=32920
http://www.daniweb.com/forums/thread148485.html
http://www.daniweb.com/forums/thread148184.html
KevinADC is offline   Reply With Quote
Old Oct 2nd, 2008, 3:18 AM   #3
annie_singh
Newbie
 
Join Date: Oct 2008
Posts: 2
Rep Power: 0 annie_singh is on a distinguished road
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...
annie_singh is offline   Reply With Quote
Old Oct 4th, 2008, 11:33 PM   #4
pan1c
Newbie
 
Join Date: Oct 2008
Posts: 2
Rep Power: 0 pan1c is on a distinguished road
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.
pan1c is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:53 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC