how can i find value of Acos without using math library of c#??i have serch for more time in the web!thank you

Edited 6 Years Ago by mikaandy83: n/a

arccos y = Pi/2 - sum((2n)!/((2^2n)*(n!)^2))*(y^(2n+1)/(2n+1) where n = 0 .. infinity and |y| <= 1.

Or you could use (if you can deal with imaginary numbers):

arccos x = -i * ln(x + i * sqrt(1 - x*x))
arccos x = pi/2 + i * ln(i * x + sqrt(1 - x*x))

Thaks Momerath but your answer is unclear for me!
my problem was to translate (arccos y = Pi/2 - sum((2n)!/((2^2n)*(n!)^2))*(y^(2n+1)/(2n+1) where n = 0 .. infinity and |y| <= 1. ) in language c#!


i not understand

Isn't that the whole point of programming, being able to translate specifications into code? This is obviously a school assignment (no one in the real world says "but you can't use the math library! OMG!") and you would learn absolutely nothing if I were to write the code for you.

So you need to go to wikipedia, look up arccos and study the formulas give there. Pick one to program and write code for it. Test it by using the Math.Cos function to generate some numbers, then use your code to covert them back.

Just FYI, the last two equations are much easier to program as they don't involve infinite series. And they use System.Numerics and not System.Math :)

Comments
Right observation

Dear Momerath Open discussion means just trying to reach a resolution, and you did not want to help! I am not a student! .. Next time if you're not going to solve the discussions did not intervene!

What have you tried for yourself?
We are all willing to help you here with your questions, but you got at least show some effort. Momerath has given you all the info you need to get started. So start to program. If you show some of your(even not working) code, we can help you better :)

Edited 6 Years Ago by ddanbe: n/a

Ok..i have traslate this method :

 static double MyACos(double x) //calculate cosine
 {
            x = Math.Abs((x + Math.PI) % (2 * Math.PI) - Math.PI);

            decimal xxx = x * x* x; //reduce amount of multiplications
            decimal xx = x * x;
            return Math.PI/2 - x -
                                  xxx / 6 - 
                                  3 * xx * xxx / 40 - 
                                  7 * xxx * xxx * x / 112;

        }

by the serie of taylor:

http://it.wikipedia.org/wiki/Arcocoseno

Edited 3 Years Ago by mike_2000_17: Fixed formatting

OK mikaandy83, now we are getting somewhere! :cool:
First remark: You are still using the Math class(Math.PI) use your own constant instead:

const double PI = 3.14159;

Second remark: Don't use the decimal type here, use double.
Decimal is used in finacial calculations.
Thirth remark: Try to add more terms to the Taylor series.
Alla prossima!

Edited 6 Years Ago by ddanbe: n/a

Hi..thaks you for your answer..i have Try to add more terms to the Taylor series but the result is incorrect,for example if i calculate ACos(0,9) the result is 0,46045 instead 0,45...!help my please !

The Taylor series needs a lot of iterations to get anywhere near the correct result. If you aren't doing 100,000 or more then you aren't going to get more than 1 or 2 decimal places of accuracy.

This article has been dead for over six months. Start a new discussion instead.