Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
* implemented sin & cos function using taylor series approximation, and got tests run for sin & cos successful

Signed-off-by: johnzhouinfo <[email protected]>
  • Loading branch information
johnzhouinfo committed Nov 5, 2019
1 parent 63b5741 commit 7cb45e9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Binary file added screenShot/Ver_2.0_ScreenShot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 68 additions & 2 deletions src/Assign_2/TrigFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,93 @@
*/
public final class TrigFunction {

/**
* Sin function using Taylor series approximation
*
* @param angRad radian
* @return
*/
public static double sin(double angRad) {
return 0.0;
double radian = convertRadian(angRad);
// compute the Taylor series approximation
double term = 1.0; // ith term = x^i / i!
double sum = 0.0; // sum of first i terms in taylor series

for (int i = 1; term != 0.0; i++) {
term *= (radian / i);
if (i % 4 == 1) sum += term;
if (i % 4 == 3) sum -= term;
}
return sum;
}

/**
* Cos function using Taylor series approximation
*
* @param angRad radian
* @return
*/
public static double cos(double angRad) {
return 0.0;
double radian = convertRadian(angRad);
// compute the Taylor series approximation
double term = 1.0; // ith term = x^i / i!
double sum = 0.0; // sum of first i terms in taylor series

for (int i = 1; term != 0.0; i++) {
term *= (radian / i);
if (i % 4 == 0) sum += term;
if (i % 4 == 2) sum -= term;
}
return 1 + sum;
}

/**
* Tan function
*
* @param angRad radian
* @return
*/
public static double tan(double angRad) {
return 0.0;
}

/**
* Cot function
*
* @param angRad radian
* @return
*/
public static double cot(double angRad) {
return 0.0;
}

/**
* Csc function
*
* @param angRad radian
* @return
*/
public static double csc(double angRad) {
return 0.0;
}

/**
* Sec function
*
* @param angRad radian
* @return
*/
public static double sec(double angRad) {
return 0.0;
}

/**
* Convert radian between -2 PI and 2 PI
*
* @param angRad input radian
* @return
*/
private static double convertRadian(double angRad) {
return angRad % (2 * Math.PI);
}
}

0 comments on commit 7cb45e9

Please sign in to comment.