|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.webcompmath.data.Constant net.sourceforge.webcompmath.data.Variable
public class Variable
A Variable is a Value object whose value can be changed. Usually, a Variable will have a name, although that is not required unless tha Variable is going to be registered with a Parser. A Variable can be used as a Value, an Expression, or an ExpressionCommand. Since it is an ExpressionCommand, it can occur as a command in an ExpressionProgram. In that case, it simply represents a variable that occurs as part of an expression.
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().
Field Summary |
---|
Fields inherited from class net.sourceforge.webcompmath.data.Constant |
---|
value |
Constructor Summary | |
---|---|
Variable()
Create an unnamed Variable with initial value 0. |
|
Variable(java.lang.String name)
Create a Variable with the given name and with initial value zero. |
|
Variable(java.lang.String name,
double value)
Create a Variable with the given name and given initial value. |
Method Summary | |
---|---|
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. |
java.lang.String |
toString()
Return a print string representing this variable. |
Methods inherited from class net.sourceforge.webcompmath.data.Constant |
---|
appendOutputString, apply, extent, getName, getVal, getValueWithCases, setName |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Variable()
public Variable(java.lang.String name)
name
- variable's namepublic Variable(java.lang.String name, double value)
name
- variable's namevalue
- initial valueMethod Detail |
---|
public void setVal(double value)
value
- value to set variable topublic Expression derivative(Variable wrt)
derivative
in interface Expression
derivative
in class Constant
wrt
- "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 ExpressionCommand
compileDerivative
in class Constant
prog
- expression programmyIndex
- location in programderiv
- the derivativewrt
- variable with respect topublic boolean dependsOn(Variable x)
dependsOn
in interface Expression
dependsOn
in interface ExpressionCommand
dependsOn
in class Constant
x
- variable to check
public java.lang.String toString()
toString
in interface Expression
toString
in class Constant
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |