/** * Sine Series */ public class sine extends series { protected int sign = 1; protected double valpos = 0.0; protected double valneg = 0.0; /** * Constructor for Sine Series * * @param x is the argument for the series */ sine(double x){ param = x; n = -1; term = 0.0; valpos = 0.0; valneg = 0.0; val = valpos; } /** * First initializes the first term of series */ public void first(){ term=param; sign=1; n=0; valpos = term; valneg = 0.0; val = valpos - valneg; } /** * Advances to the next term in the series. */ public void nextTerm(){ n++; sign = -1*sign; term = term*(param*param)/((2*n)*(2*n+1.0)); if (sign>0) valpos = valpos + term; else valneg = valneg + term; val = val + sign*term; // inaccurate way // val = valpos - valneg; // accurate way // System.out.println("n=" + n + ", sign=" + sign + ", term=" +term); } /** * Returns the value of the mth term in series * * @param m the index of a term */ public double valAt(int m){ first(); for (int i=0; i