|
Post by Camerart on Apr 9, 2018 12:36:53 GMT
Hi, I have an equasion for use in a project : arctn= x/y/( 1+0.28125*( x/y )^2)*180/pi
My system doesn't support '^' Will someone rearange the brackets with '*' instead of '^' Please? I've tried a few versions, but the results aren't correct.
Camerart.
|
|
|
Post by tenochtitlanuk on Apr 9, 2018 13:47:03 GMT
Don't understand what you mean by 'my system does not support', but the 'exponential' operator ^2 simply means multiply the number by itself, ie 3^2 is the same as 3*3. Run the following code and see both give the same result?
x =2 y =3
pi =3.14159265
arctn= x /y /( 1+0.28125 *( x /y )^2) *180 /pi print arctn
arctn= x /y /( 1+0.28125 *( x /y ) *( x /y)) *180 /pi print arctn
|
|
|
Post by tsh73 on Apr 9, 2018 14:24:21 GMT
I don't know what are you actually doing but if this means some ting like 'arctangent' en.wikipedia.org/wiki/Inverse_trigonometric_functionsthen your formula looks highly suspicious to me. Here tested JB user function to get arc tangent: function atan2(y,x) 'pi = asn(1) * 2 'global if x <> 0 then arctan = atn(y/x)
select case case x > 0 atan2 = arctan
case y>=0 and x<0 atan2 = pi + arctan
case y<0 and x<0 atan2 = arctan - pi
case y>0 and x=0 atan2 = pi / 2
case y<0 and x=0 atan2 = pi / -2 end select end function
|
|
|
Post by Camerart on Apr 9, 2018 14:35:19 GMT
Hi T and T,
My system is a PIC programmer, and simply doesn't support carets.
First I'll try the offered example: arctn= x /y /( 1+0.28125 *( x /y ) *( x /y)) *180 /pi
Thanks. C.
|
|
|
Post by B+ on Apr 9, 2018 18:33:17 GMT
Reversing x and y, Camerart's Forumula works as approach 45 degrees and then goes wrong way!
pi = acs(-1) print "check pi = ";pi print 'edit: comment from old code removed from this line print pstr$("Degrees", 10);", ";pstr$("Radians", 10);", ";pstr$("TAN", 10);", ";pstr$("ATN", 10);", ";"Camerart Formula" for degree = 0 to 90 step 5 radian = degree * pi / 180 y = cos(radian) 'reversed from normal x, y x = sin(radian) if x <> 0 then t = tan(radian) at = atn(t) * 180 / pi CamerartArcTan = x /y /( 1+0.28125 *( x /y ) * ( x /y)) * 180 /pi print pnum$(degree, 10);", "; pnum$(radian, 10);", ";pnum$(t, 10);", ";pnum$(at, 10);", ";pnum$(CamerartArcTan, 10) end if next
function pnum$(x,lenstring) pnum$=right$(space$(lenstring)+str$(x),lenstring) end function
function pstr$(x$,lenstring) pstr$=right$(space$(lenstring)+x$,lenstring) end function
Output:
check pi = 3.14159265
Degrees, Radians, TAN, ATN, Camerart Formula 5, 7266463e-1, 7488664e-1, 5, 5.00196314 10, 0.17453293, 0.17632698, 10, 10.0152148 15, 0.26179939, 0.26794919, 15.0, 15.0484862 20, 0.34906585, 0.36397023, 20, 20.1048824 25, 0.43633231, 0.46630766, 25.0, 25.1776986 30, 0.52359878, 0.57735027, 30.0, 30.244328 35, 0.61086524, 0.70020754, 35, 35.2571756 40, 0.6981317, 0.83909963, 40, 40.1301103 45, 0.78539816, 1.0, 45.0, 44.7186572 50, 0.87266463, 1.19175359, 50.0, 48.7922501 55, 0.95993109, 1.42814801, 55.0, 51.998478 60, 1.04719755, 1.73205081, 60.0, 53.8246515 65, 1.13446401, 2.14450692, 65, 53.5749845 70, 1.22173048, 2.74747742, 70, 50.4054432 75, 1.30899694, 3.73205081, 75, 43.4853373 80, 1.3962634, 5.67128182, 80, 32.34537 85, 1.48352986, 11.4300523, 85.0, 17.3508382 90, 1.57079633, 1192836e15, -90.0, 995373e-13
|
|
|
Post by Camerart on Apr 9, 2018 19:54:40 GMT
Hi B,
That's excellent work.
This is only for 0-45
I'll look closer tomorrow.
Will you explain your comment: reversing X and Y please?
Thanks,
C.
|
|
|
Post by tsh73 on Apr 9, 2018 20:37:39 GMT
I tried that formula too y = x/(1+0.28125*x*x) and got that it is indeed very close to ATN(x) for x in [0..1]
But I cannot see how that could be Taylor series Aren't they all written in a form SUM_{i=0} (c_i*x^i)?
|
|
|
Post by B+ on Apr 9, 2018 20:52:35 GMT
I tried that formula too y = x/(1+0.28125*x*x) and got that it is indeed very close to ATN(x) for x in [0..1] But I cannot see how that could be Taylor series Aren't they all written in a form SUM_{i=0} (c_i*x^i)? As a matter of fact, before checking Camerart's formula, I did try Taylor's Series! I got very good results approaching 45 degrees and then things went badly, worse than Camerart's formula. Perhaps you can see the error of my way? 'https://math.stackexchange.com/questions/29649/why-is-arctanx-x-x3-3x5-5-x7-7-dots 'arctan(x)=x-x^3/3+x^5/5-x^7/7+…?
' x probably in radians
'n th term denominator = 2n - 1 'n th term numerator = x ^ (2n - 1) 'note: 2n -1 series is just odd numbers!
'if n is even subtract term 'if n is odd add term
pi = acs(-1) print "check pi ";pi print 'test formula for arctan with 10 terms from Taylor Series for degree = 0 to 90 step 5 rad = degree * pi/180 print "degree, radian ";degree;", ";rad x = tan(rad) print "x = tan(radian) = ";x 'now the arc tangent of x should be = radian and radian * 180/pi = angle in degree sum = 0 for n = 1 to 10 oddN = 2*n - 1 numerator = x for power = 2 to oddN 'without using ^ for power numerator = numerator * x next 'add or subtract if n mod 2 = 0 then mult = -1 else mult = 1 sum = sum + mult*(numerator / oddN) next print "For angle ";degree print "The formula of arctan(tan(angle)) got ";sum * 180 / pi 'convert to degrees print print next
'something goes wrong after 40 degrees!
|
|
|
Post by B+ on Apr 9, 2018 21:04:40 GMT
Hi B, That's excellent work. This is only for 0-45 I'll look closer tomorrow. Will you explain your comment: reversing X and Y please? Thanks, C. Where you are using x and y, I would use y and x. tangent is well known as = to sin / cos. Sin is always associated to y height on graph and cos x the horizontal width on graph, so tan(angle) = y/x = "rise over run" AKA slope of a line. But your formula works better if I change x and y around, or you have an arc cotangent formula ( = x/y = the reciprocal of arc tangent).
|
|
|
Post by B+ on Apr 9, 2018 21:23:46 GMT
|
|
|
Post by tsh73 on Apr 9, 2018 21:29:53 GMT
Nothing wrong. It's all math. Sin cos exp has a member of series of a form x^n/n! n! rises really fast, so member goes to 0 and series converge real fast.
Now arctan has members in the form x^n/n 1/n really doesn't do much good with convergence (SUM 1/n is not converge at all) So the only hope that x^n will go down. But it will - only for abs(x)<1. So our series behaves only for x<1
(btw your code - Taylor formula - changed up to 20 gives 44.284249 for 45 degrees. A bit better then 43.571143 for 10 members, but still not very good. But this is really the border.)
|
|
|
Post by tsh73 on Apr 9, 2018 21:42:16 GMT
|
|
|
Post by B+ on Apr 10, 2018 2:32:06 GMT
Yes! and it shows how the error escalates after 40 degrees. Thanks tsh73, my faith in Taylor Series restored (by restricting my application of it to less than 45 degrees for arc tan).
|
|
|
Post by Camerart on Apr 10, 2018 8:27:45 GMT
Hi All,
All impressive stuff, but I am using a PIC programmer, that has quirks, which means I have to be careful leaving the suggested formula.
e,g, Oshonsoft (My simulator/programmer) has ARCTAN, but it doesn't work. This is why I'm using my word 'arctn'
As the original formula was suggested by someone who is working through the Idiosyncrasies of the programmer and the compass module I'm using, I ought to stick closely to it.
Here it is again, after conversion by T : arctn= x /y /( 1+0.28125 *( x /y ) *( x /y)) *180 /pi
Are you suggesting that I change it to : arctn= y/x /( 1+0.28125 *( y/x ) *( y/x)) *180 /pi ?
NOTE: This is only for the 0 to 45º section. NOTE 2: I've got an 'O' level in Maths and Physics, learned navigation, but still don't properly get SIN, TAN, ARCTAN etc and never will, Sorry.
C.
|
|
|
Post by tsh73 on Apr 10, 2018 9:13:07 GMT
You really have to check it by yourself. Try and see if it makes sense. Here how (x, y) usually drawn. Result of arctan is an angle. Compared are buildt-in arctg() (SMath Studio - free math package) and your formula. Second part is using your formula to get angles in 45..90. _that_ actually changes y/x to x/y. (if z is y/x then 1/z is naturally x/y).
|
|