Jump to content

[SOLVED] TAN function


GingerRobot

Recommended Posts

I've just noticed that this statement:

 

echo tan(deg2rad(360));

 

Produces an answer of -2.44921270764E-016. Yet if i put tan(360) into my calculator, the answer is 0 - which i always thought it was.

 

Perhaps ive missed some crucial part of maths somewhere along the line. As far as i know, tanx = sinx/cosx. So tanx = 0/1 (where x is 360). It was my understanding that 0 divided by anything is 0. Is this not the case?

 

Any information would be appreciated.

 

Edit: Ive just noticed that the problems seem to stem from the sin function. sin(deg2rad(360)) gives -2.44921270764E-016, rather than 0. Yet sin(deg2rad(0) does give the answer as 0. Any thoughts?

Link to comment
Share on other sites

Daniel: I suppose its possible. I can't believe im the first person ever to notice, however.

 

Tibberous: Yeah, ok, Anything divided by 0 is undefined, im with you there. However, im talking about dividing 0 by something else - which should be 0.

 

Perhaps my original statement should have been "0 divided by any other non-zero number is 0"

Link to comment
Share on other sites

It has to do with the nature of the discovery of this answer.  As i've stated in the board on higher order differentials the way computers solve trig functions is not based on a known table of values, but based on the summing of an infinite series.

http://en.wikipedia.org/wiki/Taylor_series

In this case it is solving the first X (x is probably like 100 cause a computer can do that) values of the infinite series of sin/cos thus why you are producing an answer that is approximately zero. 

The reason one produces it and the other doesn't is because there is a table of the special values predefine in most caluclations 0pi, pi/3, pi/4, pi/2 pi/6 etc etc and all variants of these.  However since you are producing an integer value from the deg2rad (using a formula) it probably isn't recognizing it as the special angle thus it calculates off the series.  try saying this and see what u get

<?php
$angle = 360;
$rad_angle = deg2rad($angle);
echo "The Tan of the angle based of its Radian Calculation is: ".tan($rad_angle)."<br/>\" \" its degree is: ".tan($angle);
?>

and see what u get

Link to comment
Share on other sites

It has to do with the nature of the discovery of this answer.  As i've stated in the board on higher order differentials the way computers solve trig functions is not based on a known table of values, but based on the summing of an infinite series.

 

Makes sense. Thanks for the information.

 

The reason one produces it and the other doesn't is because there is a table of the special values predefine in most caluclations 0pi, pi/3, pi/4, pi/2 pi/6 etc etc and all variants of these.  However since you are producing an integer value from the deg2rad (using a formula) it probably isn't recognizing it as the special angle thus it calculates off the series. 

Presumably PHP doesn't have a 'table' of special values then? Otherwise you would expect :

echo sin(pi());

To produce 0? Or have i misunderstood?

Link to comment
Share on other sites

Yeah math programing is fuzzy, because its all done via series my assumption is that php doesn't know special angles and get exact answers for them as you said but i think we have this figured out.  When in doubt round answers within a reasonable degree of certainty for your given function.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.