public class Variable extends Constant
This class implements the Expression, ExpressionCommand, MathObject, and Value interfaces (since Constant implements them).
Most methods in interfaces Value, Exprssion, ExpressionCommand, and MathObject are inherited from class Constant. The following four methods override methods inherited from that class: public Expression derivative(Variable wrt); public void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt); public boolean dependsOn(Variable x); and public String toString().
| Constructor and Description |
|---|
Variable()
Create an unnamed Variable with initial value 0.
|
Variable(String name)
Create a Variable with the given name and with initial value zero.
|
Variable(String name,
double value)
Create a Variable with the given name and given initial value.
|
| Modifier and Type | Method and Description |
|---|---|
void |
compileDerivative(ExpressionProgram prog,
int myIndex,
ExpressionProgram deriv,
Variable wrt)
Add a command to deriv to evaluate the derivative of this Variable with respect to the
Variable wrt.
|
boolean |
dependsOn(Variable x)
Check whether the value of this variable depends on the value of x.
|
Expression |
derivative(Variable wrt)
Return the derivative of this Variable with respect to the
Variable wrt.
|
void |
setVal(double value)
Set the value of this Variable to the specified value.
|
String |
toString()
Return a print string representing this variable.
|
appendOutputString, apply, extent, getName, getVal, getValueWithCases, setNamepublic Variable()
public Variable(String name)
public Variable(String name, double value)
public void setVal(double value)
public Expression derivative(Variable wrt)
derivative in interface Expressionderivative in class Constantwrt - "with respect to", i.e., the variable with respect to which to
take the derivative.public void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt)
compileDerivative in interface ExpressionCommandcompileDerivative in class Constantprog - program in which ExpressionCommand occurs.myIndex - point at which ExpressionCommand occurs in the ExpressionProgram.deriv - the derivative of the ExpressionPorgram prog, which is in the process of being computed.
Commands should added to deriv that will compute the derivative of this ExpressionCommand.wrt - commands are added to deriv with respect to this Variable.public boolean dependsOn(Variable x)
dependsOn in interface ExpressiondependsOn in interface ExpressionCommanddependsOn in class Constantpublic String toString()
toString in interface ExpressiontoString in class Constant