# Re: Magnitude of a 3d vector

On Mar 29, 5:54 pm, Clay <c...@xxxxxxxxxxxxxxx> wrote:
On Mar 27, 9:52 am, Vladimir Vassilevsky <nos...@xxxxxxxxxxx> wrote:

There was a need for quick and dirty approximation of the magnitude of
the 3-dimensional vector (x,y,z). This is what worked best:

Let x = max(x,y,z)
Then magnitude ~ x + 0.25*(y+z)
Accuracy ~ 13%

Interestingly, this provides for better accuracy then the sequential use
of the two 2d approximations (see Lyons's "Root of all evils").

DSP and Mixed Signal Design Consultanthttp://www.abvolt.com

I wrote some Monte Carlo test code and I get:

|r| = 0.90 x + 0.38 (y+z) with avg err=0 and standard deviation
(relative length) of 0.029

where x is the max of the absolute values of x,y,z and y+z is the sum
of the remaining two absolute values.

These coefs are close to minimizing the variance of the relative
error.

You are using the uniform distribution on the unit sphere, are you?

illywhacker;
.

## Relevant Pages

• Re: Magnitude of a 3d vector
... Then magnitude ~ x + 0.25* ... of the two 2d approximations (see Lyons's "Root of all evils"). ... DSP and Mixed Signal Design Consultanthttp://www.abvolt.com- Hide quoted text - ...
(comp.dsp)
• Re: Magnitude of a 3d vector
... Then magnitude ~ x + 0.25* ... of the two 2d approximations (see Lyons's "Root of all evils"). ... An add and a couple of shifts after abs() and a max ...
(comp.dsp)
• Re: Magnitude of a 3d vector
... Then magnitude ~ x + 0.25* ... of the two 2d approximations (see Lyons's "Root of all evils"). ... You are using the uniform distribution on the unit sphere, ...
(comp.dsp)
• Re: Magnitude of a 3d vector
... Then magnitude ~ x + 0.25* ... of the two 2d approximations (see Lyons's "Root of all evils"). ... of the remaining two absolute values. ...
(comp.dsp)
• Re: strtoul() behavior
... Sizes of integer types ... The values given below shall be replaced by constant expressions ... equal or greater in magnitude (absolute value) to those shown, ...
(comp.lang.c)