-2

I need to compute the law of cosines for the given values as shown above. I tested each one of the values to see if the correct computations are made for the parts of the equation. I need to find the cosine for the given angle "a" and in the equation, but the value is not computed. How can I solve this.

double b = 13; //side 
double c = 15; // other side 
double a =15; // angle 
double cosines = Math.pow(b, 2) + Math.pow(c, 2) + 2*(b)*(c) *Math.cos(Math.toRadians(a));
double test = 2*(b)*(c);
double cosiness = Math.sqrt(cosines);
System.out.println(cosiness);
System.out.println(test);
double test2 =  Math.cos(Math.toRadians(a));
System.out.println(a);
double test3 =  Math.pow(b, 2);
System.out.println(test3);
System.out.println(Math.pow(c, 2));

This outputs:

27.761683526989795
390.0
15.0
169.0
225.0

How do I correct this?

Jason
  • 11,744
  • 3
  • 42
  • 46
ecke
  • 11
  • 1
  • 1
  • 4
  • 2
    You will need to explain _"the value is not computed"_ – Jim Garrison Mar 04 '16 at 05:23
  • Please show what you expect the answer to be, and identify where you think it is going wrong. – Jason Mar 04 '16 at 05:23
  • the value for a is the angle 15 degrees. I want the program to convert it to radians then take the cosine of that value. This program does not change the value of "a". I want that value to change. I want the output to be 17. – ecke Mar 04 '16 at 05:33

1 Answers1

0

To change the value of a variable you have to use an assignment statement:

a = Math.toRadians(a);

Assignment statements are a dangerous source of bugs though. You're probably better off using a new variable.

double aRadians = Math.toRadians(a);
Joni
  • 108,737
  • 14
  • 143
  • 193