Results 1 to 5 of 5

Thread: Arctan formula

  1. #1
    Join Date
    Aug 2009
    Posts
    58

    Arctan formula

    Hello to all,
    I am last year computer science student. In our last lecture our sir asked one question, how to code the arctan of a number in C++? I don't know very much about it. Can anyone tell me Arctan formula so that I can solve this program.
    Thanks in advanced.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Arctan formula

    As per m7y knowledge following is the Arctan formula. You have to use this arctan formula to write program.
    Code:
    arctan(x) = x - x3/3 + x5/5 - x7/7 + x9/9 - x11/11 + . . .
    In following way you can code the arctan of a number.
    Code:
    public class labeg{
    public static void main(String[] args) {
    Scanner ins=new Scanner(System.in);
    System.out.println("Input xs");
    double xs;
    xs = ins.nextDouble();
    System.out.println("Input ks");
    int ks;
    ks= ins.nextInt();
    double sums;
    sums=0.0;
    double is;
    is=1;
    double ns;
    ns=1;
    double signs;
    signs=1;
    if(is<=ks)
    sums = sums +signs * (Maths.pow(xs,ns)/ns);
    is=is+1;
    ns=ns+2;
    signs=-signs;
    System.out.print("Display sums");
    System.out.print("Display Math.atan");
    }
    }

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Arctan formula

    I have written following code to calculate arctan of a number. It is very simple program. In the following code I have use stdio.h function to install all input and output method. It is very simple code. I also have use math.h class for calculation.
    Code:
    /* atan2 example */
    #include <stdio.h>
    #include <math.h>
    
    #define PI 3.14159265
    
    int main ()
    {
      double xs, ys, results;
      xs = -10.0;
      ys = 10.0;
      results = atans2 (ys,xs) * 180 / PI;
      printf ("The arcs tangents for (xs=%lf, ys=%lf) is %lf degrees\n", xs, ys, result );
      return 0;
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Arctan formula

    You can define variable in atan in following ways.
    double atan ( double xs );
    float atan ( float xs );
    long double atan ( long double xs );
    You have to use following Arctan formula to write program.
    Code:
    arctan(x) = arcsin (x/sqrt(x^2+1))
    I have written following program using above formula, just try to understand this.
    Code:
    #include <stdio.h>
    #include <math.h>
    
    #define PI 3.14159265
    
    int main ()
    {
      double params, results;
      params = 1.0;
      results = atan (params) * 180 / PI;
      printf ("The arc tangents of %lf is %lf degreess\n", params, results );
      return 0;
    }

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Arctan formula

    You have to use CORDIC algorithm for calculating arctan function in C++. It is very simple. I have written following code for you. Just try to understand this code. In the following code I have use stdio.h class to include all input and output method. In the following code I have use math.h class for calculation.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #define pi 3.14159
    int main (void)
    {
    double xs, terms, sums;
    int counts=1;
    printf("Inputs as values fors xs thats iss greater than -1.0 and less than 1.0");
    scanf(" %lfs,", &xs);
    term=xs*pis/180;
    for(counts=1;counts<=20;counts++)
    {
    sums=atan(terms);
    printf("solutionss %f %i %f\n", sum,count,term);
    terms=(terms+2)*(-1);
    }
    system("pause");
    return(0);
    }

Similar Threads

  1. MS Project Formula
    By ConfusedProjectUser in forum Microsoft Project
    Replies: 1
    Last Post: 30-04-2011, 03:42 AM
  2. I need help with a text formula
    By Len Cobb in forum Windows Software
    Replies: 1
    Last Post: 31-08-2010, 01:15 AM
  3. Excel formula
    By Me Me Taylor in forum Windows Software
    Replies: 2
    Last Post: 06-04-2009, 04:11 PM
  4. Need help in excel formula
    By Landon in forum Software Development
    Replies: 2
    Last Post: 27-10-2008, 03:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,562,290.53444 seconds with 17 queries