Rename D() to diff(), add integrate()

This commit is contained in:
skylarmt 2015-01-07 00:57:30 -07:00
parent 10e2b13e59
commit 3174ab585b
4 changed files with 27 additions and 9 deletions

View File

@ -28,8 +28,6 @@
package net.apocalypselabs.symat;
import static java.lang.Math.*;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.swing.JOptionPane;
import org.matheclipse.core.eval.EvalUtilities;
import org.matheclipse.parser.client.math.MathException;
@ -43,8 +41,7 @@ import org.matheclipse.parser.client.math.MathException;
*/
public class Functions {
private ScriptEngine symja = new ScriptEngineManager().getEngineByExtension("m");
private EvalUtilities util = new EvalUtilities(true, true);
private final EvalUtilities util = new EvalUtilities(true, true);
Graph graphwin = new Graph(true);
/*
@ -63,10 +60,28 @@ public class Functions {
*/
// Derivative of function with respect to idv
public String D(String function, String idv) {
public String diff(String function, String idv) {
return util.evaluate("diff(" + function + "," + idv + ")").toString();
}
public String diff(String function) {
// Assume "x" as var
return diff(function, "x");
}
@Deprecated
public String D(String function, String idv) {
return diff(function, idv);
}
public String integrate(String function, String idv) {
return util.evaluate("integrate(" + function + "," + idv + ")").toString();
}
public String integrate(String function) {
return integrate(function, "x");
}
public String factor(String function) {
return sym("Factor(" + function + ")");
}

View File

@ -8,7 +8,8 @@
<b>notify(var)</b> Creates a popup box with the given content.
<br><b>ask(prompt)</b> Returns the entered text.
<br><b>print(text)</b> Outputs the given text to the screen. Does not require special prefix in Python.
<br><b>D("3*x", "x")</b> Returns the derivative of the function with respect to the second argument.
<br><b>diff("x^3", "x")</b> Returns the derivative of the function with respect to the second argument.
<br><b>integrate("3*x^2", "x")</b> Returns the integral of the function with respect to the second argument.
<br><b>$("command")</b> Parses the given text with the Symja library.
<br>&nbsp;&nbsp;&nbsp;<i>Aliases: sym</i>
<br><b>replace("text", "find", "replace")</b> Returns "text" with all occurrences of "find" changed to "replace".

View File

@ -1,6 +1,7 @@
notify|return nothing|Display a message in a box.
ask|return String|Ask a question in a box. Supply question text.
D|return String|Find the derivative of the function passed with respect to the second argument.
diff|return String|Find the derivative of the function passed with respect to the second argument.
integrate|return String|Find the integral of the function passed with respect to the second argument.
rad|return double|Convert a given number in degrees to radians.
deg|return double|Convert a given number in radians to degrees.
subs|return double|Solve an equation for the second argument.

View File

@ -1,6 +1,7 @@
_.notify|return nothing|Display a message in a box.
_.ask|return String|Ask a question in a box. Supply question text.
_.D|return String|Find the derivative of the function passed with respect to the second argument.
_.diff|return String|Find the derivative of the function passed with respect to the second argument.
_.integrate|return String|Find the integral of the function passed with respect to the second argument.
radians|return double|Convert a given number in degrees to radians.
degrees|return double|Convert a given number in radians to degrees.
_.subs|return double|Solve an equation for the second argument.