-
Notifications
You must be signed in to change notification settings - Fork 1
/
Funcion.java
174 lines (116 loc) · 3.58 KB
/
Funcion.java
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package Projectofinal;
import org.lsmp.djep.djep.DJep;
import org.nfunk.jep.JEP;
import org.nfunk.jep.Node;
public class Funcion {
private static final double xvalue = 0;
private static final double Yvalue = 0;
String Exp;
static String Derivada;
JEP parser = new JEP();
public Funcion(String exp)
{
Exp=exp;
Derivada = exp;
parser.initFunTab();
parser.initSymTab();
parser.addStandardConstants();
parser.addStandardFunctions();
parser.addComplex();
parser.addVariable("x", xvalue);
parser.addVariable("y",Yvalue);
parser.setImplicitMul(true);
parser.parseExpression(exp);
}
public double eval(double x) throws Exception
{
double r=Double.NaN;
parser.addVariable("x", x);
r=parser.getValue();
return r;
}
public double evalXY(double x,double y) throws Exception
{
double r=0;
parser.addVariable("x",x);
parser.addVariable("y",y);
parser.setImplicitMul(true);
parser.setImplicitMul(true);
parser.parse(Exp);
r= parser.getValue();
return r;
}
public double [] eval(double[] x) throws Exception
{
int n=x.length;
double[] r= new double [n];
for(int i=0; i<n; i++)
{
r[i]=eval(x[i]);
}
return r;
}
public double[] rango(double x0,double xn,double d)
{
int n = (int)(Math.abs(xn-x0)/d);
double[] r=new double [n];
for(int i=0; i<n; i++)
{
r[i]=x0;
x0+=d;
}
return r;
}
public static String derivada() throws Exception {
DJep j = new DJep();
j.addStandardConstants();
j.addStandardFunctions();
j.addComplex();
j.setAllowUndeclared(true);
j.setAllowAssignment(true);
j.setImplicitMul(true);
// Sets up standard rules for differentiating sin(x) etc.
j.addStandardDiffRules();
// parse the string
Node node = j.parse(Derivada);
// differentiate wrt x
Node diff = j.differentiate(node,"x");
Node simp = j.simplify(diff);
return j.toString(simp);
}
public static String dobleDerivada( ) throws Exception {
DJep j = new DJep();
j.addStandardConstants();
j.addStandardFunctions();
j.addComplex();
j.setAllowUndeclared(true);
j.setAllowAssignment(true);
j.setImplicitMul(true);
// Sets up standard rules for differentiating sin(x) etc.
j.addStandardDiffRules();
// parse the string
Node node = j.parse(Derivada);
// differentiate wrt x
Node diff = j.differentiate(node,"x");
Node simp = j.simplify(diff);
String derivateField = j.toString(simp);
return derivada1( derivateField);
}
private static String derivada1(String Exp) throws Exception {
DJep j = new DJep();
j.addStandardConstants();
j.addStandardFunctions();
j.addComplex();
j.setAllowUndeclared(true);
j.setAllowAssignment(true);
j.setImplicitMul(true);
// Sets up standard rules for differentiating sin(x) etc.
j.addStandardDiffRules();
// parse the string
Node node = j.parse(Exp);
// differentiate wrt x
Node diff = j.differentiate(node,"x");
Node simp = j.simplify(diff);
return j.toString(simp);
}
}