0

I am attempting to calculate the Sine function of an angle entered by the user in radians. I need to print the value within a given tolerance as well. I have spent a lot of time and am making very little progress. Any help would be greatly appreciated! Thanks! My main issue is a returning a value within the given tolerance.

// Tolerance is an epsilon value ex. .00001

public static void sineCalc(double angle, double tolerance) {
    int power = 1;
    double currentAnswer = 0.0;
    int count = 0;
    double answer = 0.0;
    double difference = 0.0;
    int i = 1;

    while (difference > tolerance ||  difference == 0) {

        if (i % 2 == 0) {
            currentAnswer = -Math.pow(angle, power) / getfactorial(power);
        } else {
            currentAnswer = Math.pow(angle, power) / getfactorial(power);
        }
        answer = answer + currentAnswer;
        power = power + 2;
        difference = Math.sin(angle) - answer;
        difference = Math.abs(difference);
        count++;
        i++;


    }

    System.out.println(answer);


}
Ted
  • 1
  • 1
  • What is the tolerance ? Please edit question to show it. – paisanco Mar 05 '16 at 01:44
  • Just updated. Thank you paisanco. – Ted Mar 05 '16 at 02:56
  • Might want to look at this previous question, it's pretty similar though not an exact duplicate: http://stackoverflow.com/questions/28220855/sine-calculation-with-taylor-series-not-working?rq=1 – paisanco Mar 09 '16 at 04:36

0 Answers0