Calculating sqrt for absolute velocity

I have coded my GM862 to acquire average north/south and east/west velocities based on a difference in location (ie displacement) over a time interval. I want to calculate the resultant using pythagoras but the module doesn’t seem to accept the power operator ** or any floating values such as 0.5 in python. Has anyone successfully computed a square-root on a telit module?

Thanks

If they don’t provide a floating point, you can scale (like multiply by 1000) and take the square root of that in integer.

While its not in Python there are a couple example routines in BASIC at our Yahoo Forum

http://tech.groups.yahoo.com/group/ARMe … s/sqrt.bas

http://tech.groups.yahoo.com/group/ARMexpress/files/ SQRT V1.0_BAS

I don’t have any Telit modules, but I took a quick look at their Python manual to see what they supported. They specifically say that float is not supported, and the math library isn’t listed as an included library, so it looks like you have to do everything by hand.

It’s really easy to use successive approximation or bisection to calculate square roots of values. I describe both methods and provide C code here: http://michael.dipperstein.com/sqrt/index.html.

Viskr’s idea for multiplying by a scaling factor to get extra precision is a good idea, but you need to be careful, because the result of your square root will be multiplied by the square root of your scaling factor. If you choose a scaling factor that doesn’t have an integer square root, you won’t be helping yourself out.

E.g. sqrt(7) is about 2.646. sqrt(700) = sqrt(7 * 100) = sqrt(7) * sqrt(100) = sqrt(7) * 10 = 26.46.

Multiplying by 100 gives you an extra digit of precision for the square root.

sqrt(7000) = sqrt(7) * sqrt(1000) is about 2.646 * 31.622. That doesn’t make anything nicer.

I hope that was of some help. Good luck,

-Michael

Hey thanks you guys, I figured this might be the direction I have to go.

mdipperstein - I will take a look at your code see if it applies to my situation. I don’t need much accuracy (we’re talking +/- a few kmph’s) so I think I could get away without doing too many iterations.

cheers