assignment 2 q4
This commit is contained in:
1 file changed
+27
-4
@@ -5,18 +5,41 @@ package ca.bcit.comp1510.assignment2.q4;
|
|||||||
* don't have to write an essay but you should describe exactly what it does.
|
* don't have to write an essay but you should describe exactly what it does.
|
||||||
* Describing it will help you to understand the programming problem better.</p>
|
* Describing it will help you to understand the programming problem better.</p>
|
||||||
*
|
*
|
||||||
* @author Your Name goes here
|
* @author Braeden Sowinski
|
||||||
* @version 1.0
|
* @version 1.0.0
|
||||||
*/
|
*/
|
||||||
public class Exponential {
|
public class Exponential {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* exp calculates stuff.
|
||||||
|
* @param x double
|
||||||
|
* @return double
|
||||||
|
* */
|
||||||
|
public static double exp(double x) {
|
||||||
|
double r = 1.0;
|
||||||
|
double t = 1.0;
|
||||||
|
|
||||||
|
final double m = 1e-10;
|
||||||
|
|
||||||
|
for (int k = 1; Math.abs(t) > m; k++) {
|
||||||
|
t *= (x / k);
|
||||||
|
r += t;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describe what the main method does here.
|
* Describe what the main method does here.
|
||||||
*
|
*
|
||||||
* @param args command line arguments
|
* @param args command line arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//replace next line with your code:
|
final double min = -10.0;
|
||||||
System.out.println("Question four was called and ran sucessfully.");
|
final double max = 10.0;
|
||||||
|
for (double i = min; i <= max; i++) {
|
||||||
|
double x = exp(i);
|
||||||
|
System.out.println("x = " + i + " e^x = " + x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user