Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °
| |
|
|
You are not logged in. #1 2005-09-04 09:48:11
the formulas for sine, cosine and tangentI would like to right some simple C++ programs to do some vector calculations and stuff but I need a way to calculate sine, cosine and tangent. I take it most computers have the formula's built in somewhere but I think it might be educational (mathematicly) and good programming practice to write my own algorithm. I've seen a few differant formulas for more or less accurate calculations on the internet but the explanations are often quite confusing. Using words to express yourself is not what mathematicians do best. A logarithm is just a misspelled algorithm. #2 2005-09-05 16:14:13
Re: the formulas for sine, cosine and tangentThis may help. El que pega primero pega dos veces. #5 2005-09-06 05:35:47
Re: the formulas for sine, cosine and tangent"^" means to raise to a power. It's necessary on plain text documents that don't support superscripts. It's also an operator in many programming languages, including, I think, C/++, so you can use it in your programs to raise things to a power. El que pega primero pega dos veces. #6 2005-09-06 07:52:15
Re: the formulas for sine, cosine and tangentI wrote this in Just BASIC v1.0. Code:'Note: dangle is angle in degrees and rangle is angle in radians for dangle = 0 to 90 step 5 pi = 3.141592653589793238462643383279502884197169399375105820974944 rangle=(pi*dangle)/180 'Note: cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + ... rangleSqrd=rangle * rangle diver = 0 nextTerm = 1 cosineNow = 1 for iter=1 to 10 for d1 = 1 to 2 diver = diver + 1 nextTerm = nextTerm / diver next d1 nextTerm = 0 - nextTerm nextTerm = nextTerm * rangleSqrd cosineNow = cosineNow + nextTerm next iter print "Cosine( ";dangle;" ) = ";cosineNow next dangle Imagine for a moment that even an earthworm may possess a love of self and a love of others. #7 2005-09-06 08:39:47
Re: the formulas for sine, cosine and tangentCode looks right to me. Does it work in all quadrants (90° to 360°) ? "The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman #8 2005-09-06 09:07:21
Re: the formulas for sine, cosine and tangentIt works in all four quadrants, but the floating point math isn't that precise in this language I used Last edited by John E. Franklin (2005-09-06 09:08:39) Imagine for a moment that even an earthworm may possess a love of self and a love of others. #9 2005-09-06 22:37:08
Re: the formulas for sine, cosine and tangentMight be a good idea to first automaticly reduce the arguement. I don't know this languagel but, as the first step of the function, in C++ you could just say A logarithm is just a misspelled algorithm. #10 2005-09-07 07:17:57
Re: the formulas for sine, cosine and tangentThe following web page says you can use any value of x in the cosine summation and the sine too. Last edited by John E. Franklin (2005-09-08 00:53:55) Imagine for a moment that even an earthworm may possess a love of self and a love of others. #12 2005-09-07 22:34:42
Re: the formulas for sine, cosine and tangent
Or ... "The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman #13 2005-09-08 00:49:38
Re: the formulas for sine, cosine and tangentThose are two very nice calculators! I'm impressed. I started writing my large digit calculation program yesterday, so I'll continue with that. Plus, I'm not very good at examining programs written by others, and I like writing things from scratch. Imagine for a moment that even an earthworm may possess a love of self and a love of others. |