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

Who supplies the implementation of the "sub Normalize{...}" ?

If it comes from the package "MaterialsScript", you can access it via:

my $direction=MaterialsScript::Normalize($dipoleMoment);
(You may have to massage the parameters if it is an OO call)

(It appears that "Normalize" may not be exported by "MaterialsScript", even though you requested ":all".)

                All power corrupts, but we need electricity.

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

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

    Thanks! It seems that I need to write the sub Normalize by myself. I thought Normalize is a function in perl....

      "Normalize" means different things in different contexts.

      The one you seek could very well have already been written and available inside a free CPAN module .. You need to set the context, and search.

      If you have trouble finding a pre-written one on CPAN, post back here with an explanation of what you expect "Normalize" to do, and what kind of parameters you are passing in .. Monks are eager to help.

      It appears you are dealing with Molecular Chemistry - if so perlmol may be of interest.

                      All power corrupts, but we need electricity.

        That's cool, buddy! I am trying to obtain the unit vector of the dipole moment (a vector) using sub Normalize.

        # get dipole moment my $dipoleMoment = $setMolecule->DipoleMoment; # get the unit vector of dipole moment my $direction=Normalize($dipoleMoment);

        unit vector=±a/|a|. For example, if I want to have the unit vector of (2,-3,6), the calculation process is unit vector=±(2,-3,6)/√4+9+36=±(2/7,-3/7,6/7).

        $dipoleMoment is a vector with (X, Y, Z), I am trying to have the unit vector of $dipoleMoment, would you please write sub Normalize to fulfill this calculation?

        By the way, CPAN and perlmol are very helpful for me, thank you very much!