Inverse sin cos and tan

Hello,
I was trying to use the the Math class in java but the sin cos and tan functions only take radians, not degrees and there doesn't seem to be any functions for finding the the inverse sin cos or tan. Is there another class for doing this or were sun just in a funny mood when they wrote it ?

So you missed the methods "asin", "acos", "atan", "toRadians", and "toDegrees" in the API spec how?
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Math.html
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/StrictMath.html
Note that the to* methods are fairly new additions to the API. Conversion between radians and degrees isn't hard anyway ... multip</B>r divide by 180/Math.PI.

Similar Messages

  • ATAN2  geometric function and pasing DECFLOAT34 in Sin, cos and Tan.

    Hello,
    1) Is there any macro,Function module  or any way to use atan2 is a variation of the arctangent function in ABAP
    atan2 is available in C, C++, java but i don't seem to find it in ABAP.
    Further details : --- http://en.wikipedia.org/wiki/Atan2
    2) The current limitation for Sin , Cos and tan  geometric functions is Float.
    I am looking for a way to pass a double (DECFLOAT34) into SIn or Cos.
    I do not want to lose the accuracy by using Float.
    Can this be done ?
    Regards,
    Ajay Kulkarni

    Hello Alvaro,
    I have written the following code for atan2 accordingly but it is not as accurate as i wan't it to be.
    The results are not accurate.
    Regards,
    Ajay K
    method ATAN2.
      DATA :
           xsqr TYPE DECFLOAT34,
           ysqr TYPE DECFLOAT34,
           xysqr TYPE DECFLOAT34,
           xysqrt TYPE DECFLOAT34,
           tempa TYPE DECFLOAT34,
           tempb TYPE DECFLOAT34,
           tempc TYPE DECFLOAT34,
           x TYPE DECFLOAT34,
           y TYPE DECFLOAT34,
           atan2 TYPE f.
      data tempb_float TYPE f.
      data tempd_float TYPE f.
    x = iv_x.
    y = iv_y.
    if x = 0 and y = 0.
    ans not defined
    ELSE.
        xsqr = x * x .
        ysqr = y * y .
        xysqr = xsqr + ysqr.
        xysqrt = sqrt( xysqr ).
        tempa = xysqrt - x.
        tempb = tempa / y .
        tempb_float = tempb.
        tempd_float = atan( tempb_float ).
        tempc = 2 * tempd_float.
        ev_atan2 = tempc.
    ENDIF.
    endmethod.

  • Sin, Cos, Tan problem

    Hi i'm doing textbook problems, i'm practically new to java, and forgive my lack of math skills but I need help.
    I need to write a program that prints the values of the function y=sin(x), z=cos(x), t=tan(x) for 'x' allowing the user to enter the starting degree, ending degree, and specifying the step increments. I'm not allowed to use math methods for calculations.
    I can get most of it working just not the actual math calculations. Any help would be appreciated!

    If you're not allowed to use the Math methods then you'll need to hand craft the sin, cos and tan functions yourself.
    The Taylor Expansions for these babies could be the badgers you're after.
    Try here for an introduction.
    http://mathforum.org/library/drmath/view/53760.html

  • Sin/cos

    hey I need my program to run faster and I used to just have sin/cos tables to get values from but I need more accuracy than that. However, I dont think I need as much accuracy as the built in java functions give. I forget the exact formula for it.. its something like 1+e^3/3!+e^5/5! etc.. does anyone know how far the java function goes?

    Don't bother writing your own trigonometric functions. If you think your program runs slower by calling them (and my guess is that you haven't tested that hypothesis yet), then just make a lookup table. Have entry 0 contain the sine of 0, entry 1 contain the sine of 0.01 (radians), and so on up to entry 628 containing the sine of 6.28 radians. This table of 629 entries covers the entire circle. You can fill in this table while your program is loading by calling the regular Math.sin method.
    Then when you need to calculate the sine of an angle, round it to the nearest 0.01 radians, multiply by 100, and use that integer as an array index to get the sine.

  • How to draw a line of sin x and its area under the line?

    Hi,
    I know how to draw a line from two points. However, I do not know how to draw a line of function sin(x) and its area under the line. Anyone know where to read or how can I draw it, please help me. Thanks !!
    Calvin

    use Graphics2D:: draw(Shape)
    create a class that implements Shape, and specifically the getPathIterator methods, in these methods you should return a path iterator that follows the sin/cos curve.
    All fairly simple to do.
    rob,

  • Native sin/cos functions

    hey I was curious how much faster I could make sin/cos functions at the expense of some accuracy. I used a taylor polynomial and found that to the 3rd degree, the results of my function were accurate to about 2 decimal points. By the 5th degree, they were pretty much perfect up till past the 8th decimal, unless youre looking for numbers close to pie/2, which is where the most inaccuracy occurs (still accurate to about the 6th decimal place). I tested this against the native Math.sin function, and found that mine was about twice as fast for 3rd degree, and about 1.5 times faster for 5th degree. However, I got some very strange results when I used large numbers in the calculations, where my results were 16X faster then the native ones. Does anyone know what they use to calculate sin and cos? heres my program and results:
    public class Math
         public static double PIE = 3.14159265358979323846;
         public static double sin(double x)
              if(abs(x) <= PIE)
                   return x-x*x*x/6+x*x*x*x*x/120-x*x*x*x*x*x*x/5040+x*x*x*x*x*x*x*x*x/362880;
              double t = x/PIE;
              x = PIE * (t-(int)t);
                   return x-x*x*x/6+x*x*x*x*x/120-x*x*x*x*x*x*x/5040+x*x*x*x*x*x*x*x*x/362880;
         public static double abs(double n)
              return n<0?-n:n;
         public static void main(String[] args)
              int trials = 10000000;
              long initTime = System.currentTimeMillis();
              long time1 = 0;
              long time2 = 0;
              for(int loop = 0; loop < trials; loop++)
                   java.lang.Math.sin(PIE/trials*loop*2);
              time1 = System.currentTimeMillis()-initTime;
              initTime = System.currentTimeMillis();
              for(int loop = 0; loop < trials; loop++)
                   sin(PIE/trials*loop*2);
              time2 = System.currentTimeMillis()-initTime;
              System.out.println("System runtime: "+time1+"\nMy runtime: "+time2);
    }System runtime: 2015
    My runtime: 1594
              for(int loop = 0; loop < trials; loop++)
                   java.lang.Math.sin(loop);
              for(int loop = 0; loop < trials; loop++)
                   sin(loop);
    ....System runtime: 16453
    My runtime: 1688
    I just thought that was a little strange and was curious if anyone knew what caused it?

         public static double PIE = 3.14159265358979323846;Math.PI isn't good enough for you?
    You can always look in the src.zip at the source code.
    Did you get these polynomial approximations out of Abramowitz and Stegun? If not, go find out what that is.
    Or are these Taylor series approximations that you derived for yourself? I don't think this is a good idea.
    How much expertise do you have in numerical analysis? Can you speak to convergence rate, roundoff, and errors in your formulation? If not, you shouldn't offer it as an alternative.
    I doubt that the folks who wrote the sine and cosine used in java.lang.Math were poor programmers. It's good for you to want to understand the details, but it's naive to think that your Taylor series approximation is such a radical improvement.
    %

  • Solaris 9 Fortran sin & cos

    We have a new server running Solaris 9.
    Our old server ran Solaris 6.
    We find that Fortran sin & cos values are now slightly different for given input values.
    Since both of the Solaris versions use IEEE arithmetic with the same rounding conventions, etc. what has changed??????

    We don't believe going from 32 bits to the 64 bits of Solaris 9 is relevant (and its only in addressing, not calculations - isn't it?).
    There are other differences as well, it was the f77 compiler on Solaris 6, now it is the f90 compiler with the -f77 flag.
    But the basic point is that with IEEE arithmetic and the same rounding conventions there is a correct real*4 value for sin(2.4504421).
    Using "WRITE(6,'(F10.7)') SIN(2.4504421)" on our old machine gave 0.63742417 (hex 3F232E3B) whereas our new machine gives 0.63742411 (hex 3F232E3A).
    One of these answers is WRONG - admittedly only in the final bit, but WRONG.

  • How to Create new entry, while keeping CoS and nsRoles in tact...

    Hi,
    Here's the short version:
    How can one create a new entry/context in DS, copy the attributes from an existing entry (using JNDI) and save them in the new entry/context WITHOUT duplicating CoS or nsRole/DN info.
    Long version of the question:
    We are using DS 5.2 and Portal 6 (and messenger/calendar etc). We have our employees saved in DS. What I want to do is change a user's name/uid by copying the user's attributes (in JNDI) and create a New entry with the New uid, with all the other attributes the same. Then deleting the original entry.
    This is what I have done...
    1. Get all the employee's attributes... (abriviated)(ctx is the DirContext)
    NamingEnumeration answer = ctx.search(searchBase, filter, ctls);
    SearchResult sr = (SearchResult)answer.next();
    Attributes attrs = sr.getAttributes();
    2. Create a new employee with the same attributes (assume I use a different uid in the dn)
    ctx.createSubcontext(dn, attrs);
    This works...it copies all the attributes to the new entry -BUT- when you look at the LDIF file, it ADDS several more attributes to the new entry.
    Example: it adds the following...
    sunPortalNetletRules
    sunPortalGatewayEnableSSO
    sunPortalDesktopDpDocument
    sunPortalDesktopDpLastModifiedUser
    iplanet-am-user-auth-modules
    And about 20 others...
    Now if I am not mistaken, these are the CoS and roles that the DS uses and propagates down to the entry. But when I copy the attributes over, (using JNDI) I get these attributes too but I want to copy only the attributes that are unique and have DS handle the roles and CoS like it does for the original entry.
    Is there a way to tell the DS to just use the CoS or roles instead of duplicating all these attributes in this individual entry??? (and do it using JNDI)
    (sorry this question is sooooo long.)
    Thanks!
    Eric

    Hello Viji,
    I am extremely thank ful for the document.
    Kindly help me with below points of possible
    1)     if it is standard table (LFBK) , even then shall we will need to do the generate program 
    step in SCDO ?
    2)     does it generate Z-function module ?
    3)     do we need to call this function module at appropriate places to update the CDPOS and CDHDR 
    for changes in the standard table ?
    4)     I have already created custom business object for LFBK so that Iu2019ll be able to create entry 
    in SWEC (fyi)
    5)     how and when are the method used in the table maintenance generator called ?
    6)     Page 14 point 3 says that "Add a new entry to link the Change Document Object ZPRPS_CD and 
    table ZPRPS so that changes are recorded when table entries change."
    Does this mean that once we create SCDO and generate program, these two steps are  enough 
    for the SWED entry to create change log in CDPOS and CDHDR ?
    7)     It is understood that it is necessary that the change object in SWEC should be logged in 
    CDPOS and CDHDR only then the event would be created for the SWEC entry. is this correct ?
    in order to create change log for the change object in CDHDR and CDPOS, is the SCDO entry 
    and generate program steps enough or the methods of table  maintenance generator are also 
    required ?
    thank you very much for your time
    B

  • How to measure time difference between zero crossing of a sine wave and rise time of a pulse on a same graph?

    I have a 50Hz sine wave and a pulse signal on a same graph. The phase difference between two is between 0-90 degrees.
    Now I need to calculate the time difference between (when the sine wave crosses zero volts) and (when the pulse rises). The frequency will stay approximately same for both signals.
    The application is for a three phase generator. In simple words, when the time difference between the zero-crossing of sine wave and the pulse rises increases, that means that the load on the generator has increases.
    I am a beginner user of LabView (version 9, 2009), maybe it is a very simple problem but I've been pulling my hair out for the last few days and coudln't figure anything out. Any help would be greatly appreciated. I am using DAQ USB-6008 to measure these voltages and pulse from the generator and a sensor
    I have attached a jpg (a graph that i just made with excel to explain). The time 't' is what I am trying to measure
    Cheers
    Awais 
    Message Edited by awais.h on 03-30-2010 11:20 PM
    Message Edited by awais.h on 03-30-2010 11:21 PM
    Solved!
    Go to Solution.

    Hi
    Thanks for the code but I'm afraid it won't work. Like you said the probability of choosing a value that is on both graphs may not happen. This is something that I would like the code to do automatically.
    But I did use the previous code posted and made some modifications to it and it seems to work perfectly. Now the next thing is to be able to get just that one value that tells you the first time difference.
    Here is what I get using that code.
    As you can see from the t Values. I only need the one that is highlighted. If there is a way to filter out the rest it would be great.
    I was thinking of a while loop and as soon as the value is higher than 3E-5 it would store the number and stop the loop, but I'm not too familiar with arrays in labview.
    Here is the the code modified.
    As you can see, it wasn't that big of a modification and it still is your code.
    I will keep trying.
    Thanks for the help
    Attachments:
    FinalShockSpeed.vi ‏55 KB

  • How to create sine wave and step input using cwgraph in VB 6.0

    hello..
    i'm doing my master's project now. i'm stuck on how to create a sine wave and a step input using the cwgraph using VB 6.0. please help. thanks.

    hello..thank for the reply.
    i'm having problem with my coding using cwgraph. can anyone help. everytime i do the full compile, there's error.but it can still can run, but can't convert to application form.for your info, i'm using RTscope and cwgraph to plot graph.the error is in the cwgraph coding.below are part of the coding with error. and can somebody tell me how to add cwgraph component in the VB? i try adding component, but it's not in the list of component,and i've browse for it already too.i'm doing the software at home, but i'can run it at my lab cause cwgraph component is not listed.please help.
    Dim countTime As Integer, count1 As Integer, countFreq As Integer, countVolt As Integer
    Private Sub cmdRun_Click()
    If cmdRun.CausesValidation = True Then
    cmdPause.CausesValidation = False
    tmrOsc2.Enabled = True
    tmrOsc3.Enabled = True
    Else
    cmdPause.CausesValidation = False
    tmrOsc2.Enabled = False
    tmrOsc3.Enabled = False
    For count1 = 0 To 100
    Data1(count1) = 0
    Data2(count1) = 0
    RT1.Value(1, count1) = 0
    RT1.Value(2, count1) = 0
    RT1.Refresh
    CWGraph2.Plots(1).PlotY count1 ' THIS CODING HAS AN ERROR ...
    CWGraph2.Plots(2).PlotY count1 ' THIS CODING HAS AN ERROR ...
    Next count1
    End If
    End Sub

  • Generate n sine waves and add them together

    Hi
    I'm new to Labview and I want to generate n number of sine waves and add them together to form one signal that can be out put through a DAQ card. Each successive wave frequency will be the multiple of a base wave all will be the same amplitude.
    This to me suggested a For loop with a sig generator  and a passback in it but when I tried this it threw an error because the dt were different.
    Any help will be appreciated.
    Thanks

    Show us what you did.
    LabVIEW Champion . Do more with less code and in less time .

  • Rotating, need help with cos, and sin.

    I was reading through the fourmns and have learned that I need to convert to degrees. How do I do that? another issue is, the lines are plotted with INT values and can only be int. How do I do this with ints.
    Actually, I have a scale funtion I would like to be float, but the drawRect only accepts ints. Any way of doing this.
    Here is my code. How do I do this properly.
    thanks
    //gets the new points for the rotation. passing in degrees
         public int [] rotation(int vx, int vy, int d, Graphics g)
         //using this to pass the points I need to main
         int [] tp = new int [2];
             //[row] [col]
         int[][] TM = {{Math.cos(d),-Math.sin(d), 0},
                    {Math.sin(d), Math.cos(d), 0},
                    {       0,         0,        1}}; 
             int [][] Op ={{ vx, vy, 1}};
             int [][] TD = new int [1][3];
             //gets the X + TX // Y +TY and 1 value
             TD[0][0] = Op[0][0]*TM[0][0] + Op[0][1]*TM[0][1] + Op[0][2]*TM[0][2];   // {{TX}
             TD[0][1] = Op[0][0]*TM[1][0] + Op[0][1]*TM[1][1] + Op[0][2]*TM[1][2];  //   {TY}
             TD[0][2] = Op[0][0]*TM[2][0] + Op[0][1]*TM[2][1] + Op[0][2]*TM[2][2]; //    {1 }   
             //holds the new cordinate to plot using this cause I dont need the 1
             tp[0] = TD[0][0];
             tp[1] = TD[0][1];
           return tp;
        }

    yeah, here is an example the teacher had. His had 0, and 1's. Im not really sure about it.
    Every math teacher I had skipped trig stuff and cos, sin.
                                                                                              why again?
    | cos90    -sin90      0  |         | 100 |        0  -1   0     |100|      -200
    | sin90      cos90      0 |         | 200 |   =  1   0   0      |200|   =  100
    |   0                0          1  |         |   1   |         0  1    1     |  1   |          1yikes, nothing lined up!! sorry about that. Not sure how to fix it with this little window for edit.
    reilley35

  • Inverse trigonmetric functions and MIDP

    The inverse (arc) trigonometric functions, which are static methods of the java.lang.Math class, are not included in MIDP. This seems arbitrary to me, since MIDP is used in robotics (viz. the SunSPOT), navigation is important in robotics, navigation requires working with angles, and the inverse trigonometric functions are the only functions that return an angle supported by the Math class. For instance, the angle between two vectors can be computed using arctan() or arctan2().
    I have worked around this problem by implementing arctan2 using the CORDIC algorithm (see http://en.wikipedia.org/wiki/CORDIC). Yet, I am still perplexed by the decision of leaving the inverse trigonometric functions out of MIDP. Can anyone provide the rationale? Is there a library class that provide these functions?

    It was a pain in the ass, but I was finally able to find a way to do it. spline interpolation was actually the easiest to understand, I just don't know where you put the values to form an equation you can use. I found this equation:
    P(t) = (1-t)^3P0 + 3(1-t)^2tP1 + 3(1-t)t^2P2 + t^3P3
    which actually gave me a headache, but, after looking at it, it actually works. The reason I need the arcsine and arccosine is for the Side Angle Side and related equations, a few have solutions such as sin(a) = ...... and I need a way to "unsine" that, which can only be done using the arcsine. But anyway, with this equation, say I have the equation solved, and it looks like sin(a) = .25. Normally you'd just arcsine .25, but when you can't, you can use that table, like you said before, that has values and their arcsines going from 0 to 1, in increments of 0, 0.00001, 0.00002, 0.00003, etc. you'd just take the precalculated arcsines of 0.24998, 0.24999,0.25001,0.25002, and plug them into the equation. Granted, if you had this table of values, you'd already have the precalcuated arcsine of .25, but I'm just giving this as an example. If I had say. 25938430289483.... then this table would be useful. Anyway, with the values plugged in, the equation would look like this:
    t = .25
    P0 = arcsine(0.24998)
    P1 = arcsine(0.24999)
    P2 = arcsine(0.25001)
    P3 = arcsine(0.25002)
    P(t) = (1-t)^3P0 + 3(1-t)^2tP1 + 3(1-t)t^2P2 + t^3P3
    if the equation is filled with the values, the result is a value near what the arcsine of .25. I don't know what the other methods you were talking about, but this works, and it works pretty well. I appreciate the help, this is actually an optimal solution, I'll just save the table as a serialized object(an ArrayList or something similar), and load it via the midlet. The table shouldn't be to large, and I'll adjust the accuracy based upon my space limitations. Thanks for the help, I can't believe this actually works!

  • Simultaneous analog output 1k sine wave and data acquisition

    Although many topics of simultaneous analog output and input can be found in NI Developer Zone, I have not found a case similar to my project. I'm trying to generate a 1kHz sine wave by using the analog output of NI DAQPad-6070E, and acquire one channel input signal simultaneously. I found most of the examples can not work properly above 100Hz. Any suggestions are welcome. Thank you.
    Jian

    I have sucessfully solve the problem when I observed the increase of
    scan backlog number. Simply increase the buffer size of AI/AO and you
    can make the 1kHz sine wave output and data acquired properly.
    On Tue, 3 Feb 2004 09:03:07 -0600 (CST), jujian wrote:
    >Although many topics of simultaneous analog output and input can be
    >found in NI Developer Zone, I have not found a case similar to my
    >project. I'm trying to generate a 1kHz sine wave by using the analog
    >output of NI DAQPad-6070E, and acquire one channel input signal
    >simultaneously. I found most of the examples can not work properly
    >above 100Hz. Any suggestions are welcome. Thank you.
    >
    >Jian

  • Question re. setting COS and DSCP fields

    Hi folks,
    I have two vidio codec devices, one at the core site and another at a remote site. I have an IP telephoney solution with QOS configured. The catalyst 3560 access switches are configured to trust the COS settings on trunk ports from IP handsets.
    I need to set the COS field on the access ports from the codecs to match that set by the IP phones to give eqaul prioritised status on the uplink from the access layer switch.  I also need to set the DSCP field to prioritise the traffic end to end.  My questions are how do I change the COS field on ingress to the switch port? And where and how do I change the DSCP filed i.e. at the switch or the router?
    Thanks in advance,  Shane.

    Yes you should be seeing the logo, but everyone's getting the red X instead - it's a bug introduced by the 10.1.2 update (as is the appearance of the "i" icon at the top right, where we should have the templates menu icon) but it doesn't affect the function of the dialog. What appears on the left-side panel and in the Advanced tree depends on what's in the file - some have more XMP structure than others.

Maybe you are looking for