Math Troubles

  • Thread starter Thread starter Typpo
  • Start date Start date
T

Typpo

Hi,

Maybe I'm missing something:

<begin code>
MessageBox.Show("a = " + a + ", b = " + c + ", c = " + c); //message 1

double top = (Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2));
double bottom = (2.0 * a * b);

MessageBox.Show("top = " + top + ", bottom = " + bottom); //message 2

return Math.Acos(top / bottom);
</end code>

Message 1 displays, "a = 15, b = 18.027..., c = 10".
Message 2 displays, "top = 450, bottom = 540.832...".

Which is all correct. The method itself returns 0.588, which leads me
to believe that Math.Acos is the wrong way to go about finding the
answer. On a TI-83 calculator, the functionality I'm looking for is
marked as cos^-1 (inverse cosine), which is right above the cos button.
The angle in question should be calculated as roughly 33.7 degrees.

What's wrong with the math?

Thanks.
 
It is standard practice to use radians instead of degrees. .NET makes
no exception. 0.588 radians converted to degrees is 33.7. The same is
true of logarithms regarding the base. Base e is used instead of base
10.

Brian
 
Thanks. Correct returned value should be:
return ((Math.Acos(top / bottom)) * (180.0 / Math.PI));
 
Typpo said:
Hi,

Which is all correct. The method itself returns 0.588, which leads me to
believe that Math.Acos is the wrong way to go about finding the answer.
On a TI-83 calculator, the functionality I'm looking for is marked as
cos^-1 (inverse cosine), which is right above the cos button. The angle in
question should be calculated as roughly 33.7 degrees.

What's wrong with the math?

Hi,

As Brian stated, the result is in radians and not degrees.

Multiply your result by 180/ Math.PI and you will get 33.7 degrees

Bill
 
Typpo said:
Which is all correct. The method itself returns 0.588, which leads me to
believe that Math.Acos is the wrong way to go about finding the answer.
On a TI-83 calculator, the functionality I'm looking for is marked as
cos^-1 (inverse cosine), which is right above the cos button. The angle in
question should be calculated as roughly 33.7 degrees.

What's wrong with the math?

33.7 degrees = 0.588 radian.
 
Back
Top