From: Leland Brown (lelandbrown_at_[hidden])
Date: 2006-06-15 17:33:06
--- Michael Fawcett <michael.fawcett_at_[hidden]> wrote:
> I was under the impression that the vector<3,
> free_quantity> syntax was just one alternative to
> the lengthier one,
That was my understanding too. I see no reason to
preclude the type parameter from being free_quantity,
and this would automatically allow mixed vectors - and
automatically ensure they're only used in ways that
Operations on these vectors will call operations on
their elements, and those individual operations on
free_quantity will still check for consistency of
dimensions and produce errors if the mathematics
doesn't make sense.
An example may help. Consider these vector
v1 = 1 * meter();
v1 = 2 * meter() / second();
v2 = 3 * gram();
v2 = 4 * gram();
v3 = 5 / second();
v3 = 6;
Then v1.magnitude() will produce an error, because it
involves adding (1 m)^2 + (2 m/s)^2, and the +
operator on free_quantity should complain that the
dimensions are not consistent.
On the other hand, v2.magnitude() could be allowed -
it's a straightforward computation; the result is 5 g.
Likewise, the dot product v1.dot(v3) can be done:
v1.dot(v3) = (1 m)*(5/s) + (2 m/s)*6
= 5 m/s + 12 m/s
= 17 m/s
Here the computation succeeds because both terms in
the sum have the same dimensions (velocity).
> in fact, I got the impression that Leland Brown
> currently uses mixed
> type vectors and matrices with success.
Yes. In fact my dot product example above is exactly
the kind of thing that occurs in my algorithm many,
many times (except that it more often involves
matrices as well and not just vectors).
My application involves a set of input quantities of
different dimensions, which influence the output of a
process. We need to find the best set of inputs to
get the right outputs. If there are N inputs and M
outputs, then it involves MxN matrices. The same kind
of problem comes up in a variety of engineering
disciplines. The math is the same regardless of
whether the input (or output) quantities have equal
dimensions. In my case, they do not, so I need mixed
vectors and matrices.
Another example is a covariance matrix, describing the
statistical relationships between quantities of
different dimensions. In this case, the elements of
the matrix will have many different dimensions. And a
common computation called "propagation of errors"
requires this matrix to be multiplied by other
matrices of mixed dimensions.
But a key point is: always, as in my dot product
example, the individual addition operations will end
up having consistent dimensions if the matrices have
been designed correctly. And if they haven't - well,
that's exactly where using PQS with a matrix library
is really useful to spot the error!
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk