Results 1 to 6 of 6

Thread: Math.cos()

  1. #1
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Smile 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

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  3. #3
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    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
    java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread:java3)

    Thanks for any help I get

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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.

  5. #5
    DavidG24 is offline Member
    Join Date
    Apr 2009
    Posts
    49
    Rep Power
    0

    Default

    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.

    i.e. (sourced directly from Javadoc)

    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.

    Javadoc for Math Library
    The earlier you get used to reading the Javadoc, the less painful learning new packages will be.

    I understand that being new to Java, a lot will not make sense, if you are not use to thinking in a programming framework, i.e. If you are new to the language, I can't recommend enough to hit up the likes of W3Schools Online Web Tutorials, this forum and most importantly get a book or two from the library and ploughing through them, its the best way to learn (IMO).
    There is a reason why they call it a language, don't expect to be able to 'talk' to the computer in Java in a week or two, and moreover, don't think because you know two or three words that you can complete a sentence :-)

  6. #6
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    Thanks alot for the help. I think it solved the problem. I used netbeans and that sorted it out for me, just a silly mistake.

    cheers for that

Similar Threads

  1. Using math.round
    By Hype in forum New To Java
    Replies: 3
    Last Post: 01-30-2011, 11:57 PM
  2. Create Math.sin without math.sin
    By vudoo in forum New To Java
    Replies: 11
    Last Post: 12-07-2010, 06:23 AM
  3. Need help with math equation
    By annabellastorm in forum New To Java
    Replies: 4
    Last Post: 01-10-2010, 05:12 PM
  4. Math.random()
    By Dieter in forum New To Java
    Replies: 4
    Last Post: 09-14-2009, 09:28 AM
  5. Math Program
    By stlboi in forum New To Java
    Replies: 8
    Last Post: 04-02-2009, 09:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •