in reply to Re^4: The problem of getting the unit vector "Undefined subroutine &main::Normalize"
in thread The problem of getting the unit vector "Undefined subroutine &main::Normalize"

windcrazy86:

If you know the formula (i.e., how to create the result by hand) you shouldn't have any difficulty in creating the subroutine yourself. What difficulty are you having with it?

As I see it, you'd start with something like:

sub Normalize { my $v = shift; my $vSquared = InProduct($v, $v); my $divisor = ... square root of sum of components of vSquared ... my $newVec1 = ... vector created by components of v divided by posi +tive divisor ... my $newVec2 = ... vector created by componets of v divided by negat +ive divisor ... .... whatever else is needed ... return $stuff; } my @dipoleMomentVectors = Normalize($dipoleMoment);

...roboticus

When your only tool is a hammer, all problems look like your thumb.

  • Comment on Re^5: The problem of getting the unit vector "Undefined subroutine &main::Normalize"
  • Download Code

Replies are listed 'Best First'.
Re^6: The problem of getting the unit vector "Undefined subroutine &main::Normalize"
by windcrazy86 (Novice) on Aug 31, 2017 at 20:34 UTC

    Thanks, I am new to perl, so I am still reading the tutorial online. I will test your code and see what's going on.