forked from Sukhdev841/Numerical-Methods
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths_function.java
More file actions
54 lines (46 loc) · 1.55 KB
/
Copy paths_function.java
File metadata and controls
54 lines (46 loc) · 1.55 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
public class s_function
{
private s_expression function_exp;
private s_variable_table variables;
public s_function(String expression)
{
function_exp = new s_expression(expression);
this.variables = this.function_exp.get_variables_table();
}
public s_variable_table get_variables_table()
{
return variables;
}
public Float get_value(s_variable_table table)
{
return function_exp.evaluate(table);
}
public String get_expression()
{
return this.function_exp.get_expression();
}
public static s_function add(s_function f1,s_function f2)
{
String functional_expression = "("+f1.function_exp.get_expression() + ")+(" + f2.function_exp.get_expression()+")";
s_function s = new s_function(functional_expression);
return s;
}
public static s_function subtract(s_function f1,s_function f2)
{
String functional_expression = "("+f1.function_exp.get_expression() + ")-(" + f2.function_exp.get_expression()+")";
s_function s = new s_function(functional_expression);
return s;
}
public static s_function multiply(s_function f1,s_function f2)
{
String functional_expression = "("+f1.function_exp.get_expression() + ")*(" + f2.function_exp.get_expression()+")";
s_function s = new s_function(functional_expression);
return s;
}
public static s_function divide(s_function f1,s_function f2)
{
String functional_expression = "("+f1.function_exp.get_expression() + ")/(" + f2.function_exp.get_expression()+")";
s_function s = new s_function(functional_expression);
return s;
}
}