# Math.cos()

• 03-26-2011, 03:01 AM
ravi1
Math.cos()
Hello, I am trying to calculate a very complex calculation that involves sines x cosines and dividing by cosines etc etc etc.

For example if I want to calculate the Math.cos(x + c+ s) where x,c and s are numbers, it gives me a wrong ans and multiply with cos(x).sin(x^2),

how do I do it?

Any help would be appreciated.

Cheers
• 03-26-2011, 03:24 AM
pbrockway2
Quote:

if I want to calculate the Math.cos(x + c+ s) where x,c and s are numbers, it gives me a wrong ans

Post a SSCCE: some brief, runnable code. Say what output it produces as well as what output you were expecting. In other words elaborate on what "wrong" means in this context.
• 03-26-2011, 09:54 AM
ravi1
double a= Math.cos(12.26);
double b = 19.635;
double c = Math.tan(a/b);
double d = Math.sin(c);

double e = a * (a/b);

double g= a * a* (ss * ((b)/(c*d)));

double h =a *a * (ss * ((e)/(g*a)));

This is something in similar lines.

The ans I get in java for g and h is not equal, if I calculate it using a calculator and I am getting exception on my screen while calculating, is this normal. i get exceptions like

event dispatch thread exceptions, could this be the problem

most of the exceptions show something similar to this

Thanks for any help I get
• 03-26-2011, 10:20 AM
sunde887
This isn't a short compilable bit of code, it's just some random lines. Also, you paraphrasing errors isnt helping, is there a GUI to this code? Post the exact error messages and a small program that can be compiled and run.
• 03-26-2011, 03:18 PM
DavidG24
hey mate,

I have to say I agree with what was posted before, what exactly are you trying to do??

Given you are using the trig functions from the Math library, I thought you should know that that the angle a taken as the single argument (angle 'a') for sin, cos, tan, etc measure in radians.

for Sin -

sin

public static double sin(double a)
Returns the trigonometric sine of an angle. Special cases:
If the argument is NaN or an infinity, then the result is NaN.
If the argument is zero, then the result is a zero with the same sign as the argument.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Parameters:
a - an angle, in radians.
Returns:
the sine of the argument.