-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExponent.java
More file actions
79 lines (69 loc) · 2.06 KB
/
Exponent.java
File metadata and controls
79 lines (69 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* @author Rakith (Jay) Jayewardene
* Creates a class named Exponent that extends Function
*/
public class Exponent extends Function{
/* Stores the input value */
private double inputValue;
/* Stores the operand */
private Function operand;
/**
* A constuctor for exponent that takes a function that is the operand of an exponential function
* @param operand
*/
public Exponent(Function operand) {
this.operand = operand;
}
/**
* Method that gets the operand
* @return operand
*/
public Function getOperand() {
return operand;
}
/**
* Method that takes a double as input and returns its exponential value
* @return the exponential value of the inputValue as a double
*/
@Override
public double value(double inputValue) {
return Math.exp(getOperand().value(inputValue));
}
/**
* Method that takes no input and returns the exponential value of the operand
* @return exponential value of Function
*/
@Override
public double value() {
return Math.exp(getOperand().value());
}
/**
* Method that takes the derivative of the exponential function
* @return the derivative of the exponential function
*/
@Override
public Function derivative() {
return new BinaryOp(getOperand().derivative(), new Exponent(getOperand()),BinaryOp.Op.MULT);
}
/**
* Method that converts the exponential function to a String
* @return String representation of the exponential function
*/
@Override
public String toString() {
return "Exp" + "[" + getOperand().toString() + "]";
}
/**
* Method that compares an Object named function to the exponential function
* @return true if the Object is equal to the exponential function or false if it is not equal
*/
@Override
public boolean equals(Object function) {
if(function instanceof Exponent) {
if (this.inputValue == ((Exponent)(function)).value()) {
return true;
}
}
return false;
}
}