Math Troubles

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.
 
B

Brian Gideon

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
 
T

Typpo

Thanks. Correct returned value should be:
return ((Math.Acos(top / bottom)) * (180.0 / Math.PI));
 
B

Bill Butler

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
 
M

Michael A. Covington

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top