-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCos.java
More file actions
77 lines (66 loc) · 1.88 KB
/
Cos.java
File metadata and controls
77 lines (66 loc) · 1.88 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
/**
* @author Rakith (Jay) Jayewardene
* Creates a class named Cos that extends Function
*/
public class Cos extends Function {
/* Stores the operand */
private Function operand;
/* Stores the input value */
private double inputValue;
/**
* A constructor that takes an input of operand
* @param operand
*/
public Cos(Function operand) {
this.operand = operand;
}
/**
* A method that takes no input and gets the operand
* @return the operand
*/
public Function getOperand() {
return operand;
}
/**
* Method that takes a double named inputValue and returns the cosine value of it
* @return the cosine value of the input as a double
*/
@Override
public double value(double inputValue) {
return Math.cos(getOperand().value(inputValue));
}
/**
* Method that does not take input and throws an UnsupportedOperationException
*/
@Override
public double value() {
throw new UnsupportedOperationException();
}
/**
* Method that takes no input and takes the derivative of the cosine function
* @return type function
*/
@Override
public Function derivative() {
return new BinaryOp(new BinaryOp(new Number(-1), getOperand().derivative(),BinaryOp.Op.MULT), new Sin(getOperand()), BinaryOp.Op.MULT);
}
/**
* Method that converts the function to a string
* @return the String of the cosine function
*/
@Override
public String toString() {
return "Cos[" + getOperand().toString() + "]";
}
/**
* Method that compares an Object function to the cosine function
* @return true if the Object and cosine function are equal or false if they are not
*/
@Override
public boolean equals(Object function) {
if(function instanceof Log) {
return true;
}
return false;
}
}