Sinx

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mia023
    New Member
    • May 2007
    • 89

    #1

    Sinx

    i was wondering if i could compute sin x using Taylor series my code was as follows i guess it is not correct. Tell me please what is wrong and what i should do. I guess there are alot of errors in the code(logical... )

    [CODE=java]public class Sin{
    public static void main(String []args){
    double x=Double.parseD ouble(args[0]);
    int stop=25;
    int n=0,product=1;
    double sum=0.0;
    double sign=Math.pow(-1,n+1);
    for(int i=1;i<stop;i=i= i+2){
    sum+=sign*Math. pow(x,i);
    }
    for(int i=1;i<stop;i=i+ 2){
    product*=i;
    int frac=(int)(sum/product);


    }
    System.out.prin t(frac);
    }
    }[/CODE]
    Last edited by RedSon; Oct 24 '07, 08:20 PM. Reason: CODE tags
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      Originally posted by RedSon
      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      MODERATOR
      Apparently you did not read my previous message, since you responded again (twice) without using code tags and repeating your original statement. You do not need to post the same thing over and over to get a response. You do need to post your code using CODE tags. Do not make me warn you again because that will be the third time.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        @OP: can you write down the first few terms of the Maclaurin series for us? You
        want the Taylor series with a derivative w.r.t. x at x == 0. Just the mathematical
        formula, no Java source code is needed.

        kind regards,

        Jos

        Comment

        Working...