Construct braids from complex array
jeanluct opened this issue · 5 comments
In finishing the book I realized it would be easy/useful to allow
b = braid(Z)
where Z is a K x N array of complex numbers describing the orbit of N particles.
This is easy to implement, but there's one small catch. There's logic in the braid constructor to allow for
b = braid(XY)
when XY is K x 2. In that case a warning is issued (BRAIDLAB:braid:braid:onetraj
), and a braid of 1 particle is created (identity), assuming the user means K x 2 x 1.
In Matlab there is no way to have a singleton dimension as the last dimension. So we would lose the ability to create a trivial braid of one strand, unless perhaps it is specified as a complex orbit?
Could the braid(Z)
case be triggered by detecting the complex type (rather than the dimension)?
Alternatively, a fix could be to specify braid(Z)
as accepting K x 1 x N
(second dimension always singleton), but this may be an abomination.
Could the
braid(Z)
case be triggered by detecting the complex type (rather than the dimension)?
Yeah, I'm considering that but it is also unsatisfying, since real is reasonable.
Alternatively, a fix could be to specify
braid(Z)
as acceptingK x 1 x N
(second dimension always singleton), but this may be an abomination.
Nooooo!
It's such an edge case to create single-strand braids anyways. I'll try to maybe print a warning.
There might be a way out.
>> help isreal
isreal True if input does not use complex storage.
isreal(X) returns logical 1 (true) if X does not have an imaginary
part, and logical 0 (false) otherwise. isreal returns logical 0 (false)
for complex values that have zero imaginary part, since the value is
still stored as a complex number.
Some common related commands are:
~isreal(X) detects arrays that have an imaginary part, even if it is
all zero.
~ANY(IMAG(X(:))) detects strictly real arrays, whether X has
an all zero imaginary part allocated or not.
Examples:
1) x = magic(3);
isreal(x)
The result is true because x is not a complex array.
2) y = complex(x);
isreal(y)
The result is false because COMPLEX returns y with an all zero
imaginary part.
See also real, imag, complex, i, j.
Documentation for isreal
Other functions named isreal
isreal
returns false even if an array has 0 imaginary part, when it is created with complex
.
So if a user really wants to create a single-strand braid with a complex trajectory of real numbers, they could do
>> z = [0 0] % fixed strand
>> b = braid(complex(z))
ans = < e >
or at least that's the desired output.
Here's the example that I left as a comment in braid.m
:
%
% Example:
%
% >> Z = [1 1 1 ; 2 2 2]'
% >> braid(Z)
%
% will return the identity braid on one strand (and print warning).
%
% >> braid(complex(Z))
%
% will return the identity braid on two strands.
%