Skip to content

conjugate vectors; length of complex vectors #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Math/Vector.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ class Math::Vector
$a ⋅ $b;
}

method conjugate()
{
return Math::Vector.new(@.coordinates>>.conjugate);
}

method Length()
{
sqrt(self ⋅ self);
sqrt(self ⋅ self.conjugate).abs;
}

multi method abs()
Expand Down
3 changes: 3 additions & 0 deletions t/01-basics.t
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,7 @@ isa_ok($vl, Math::VectorWithLength, "Variable is of type Math::VectorWithLength"
my $vlc = eval($vl.perl);
isa_ok($vlc, Math::VectorWithLength, "eval'd perl'd variable is of type Math::VectorWithLength");

my $complex_vector = Math::Vector.new(0, 3+4i);
is($complex_vector.abs, 5, "length of vector with complex vector is real");

done;