Source Code Cross Referenced for Variable.java in  » Science » jcm1-source » edu » hws » jcm » data » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » jcm1 source » edu.hws.jcm.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*************************************************************************
002:         *                                                                        *
003:         *   1) This source code file, in unmodified form, and compiled classes   *
004:         *      derived from it can be used and distributed without restriction,  *
005:         *      including for commercial use.  (Attribution is not required       *
006:         *      but is appreciated.)                                              *
007:         *                                                                        *
008:         *    2) Modified versions of this file can be made and distributed       *
009:         *       provided:  the modified versions are put into a Java package     *
010:         *       different from the original package, edu.hws;  modified          *
011:         *       versions are distributed under the same terms as the original;   *
012:         *       and the modifications are documented in comments.  (Modification *
013:         *       here does not include simply making subclasses that belong to    *
014:         *       a package other than edu.hws, which can be done without any      *
015:         *       restriction.)                                                    *
016:         *                                                                        *
017:         *   David J. Eck                                                         *
018:         *   Department of Mathematics and Computer Science                       *
019:         *   Hobart and William Smith Colleges                                    *
020:         *   Geneva, New York 14456,   USA                                        *
021:         *   Email: eck@hws.edu          WWW: http://math.hws.edu/eck/            *
022:         *                                                                        *
023:         *************************************************************************/package edu.hws.jcm.data;
024:
025:        /**
026:         * A Variable is a Value object whose value can be changed.  Usually, a Variable will have
027:         * a name, although that is not required unless tha Variable is going to be 
028:         * registered with a Parser.  A Variable can be used as a Value, an Expression,
029:         * or an ExpressionCommand.  Since it is an ExpressionCommand, it can occur
030:         * as a command in an ExpressionProgram.  In that case, it simply represents a variable
031:         * that occurs as part of an expression.
032:         * <p>
033:         * This class implements the Expression, ExpressionCommand, MathObject,
034:         * and Value interfaces (since Constant implements them).
035:         * <p>
036:         * Most methods in interfaces Value, Exprssion, ExpressionCommand, and MathObject
037:         * are inherited from class Constant.  The following four methods override
038:         * methods inherited from that class:
039:         * public Expression derivative(Variable wrt);
040:         * public void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt);
041:         * public boolean dependsOn(Variable x); and
042:         * public String toString().
043:         */
044:        public class Variable extends Constant {
045:
046:            /**
047:             * Create an unnamed Variable with initial value 0.
048:             */
049:            public Variable() {
050:                super (0);
051:            }
052:
053:            /**
054:             * Create a Variable with the given name and with initial value zero.
055:             * (The name can be null.)
056:             */
057:            public Variable(String name) {
058:                super (name, 0);
059:            }
060:
061:            /**
062:             * Create a Variable with the given name and given initial value.
063:             * (The name can be null.)
064:             */
065:            public Variable(String name, double value) {
066:                super (name, value);
067:            }
068:
069:            /**
070:             * Set the value of this Variable to the specified value.
071:             */
072:            public void setVal(double value) {
073:                this .value = value;
074:            }
075:
076:            /**
077:             * Return the derivative of this Variable with respect to the
078:             * Variable wrt.  The answer is 1 if wrt is this Variable.
079:             * Otherwise, the answer is 0.
080:             * @param wrt "with respect to", i.e., the variable with respect to which to
081:             *            take the derivative.
082:             * @return a constant: 1 if wrt is this Variable, 0 otherwise.
083:             */
084:            public Expression derivative(Variable wrt) {
085:                return new Constant((wrt == this ) ? 1 : 0);
086:            }
087:
088:            /**
089:             * Add a command to deriv to evaluate the derivative of this Variable with respect to the
090:             * Variable wrt. The derivative is a command for pushing either 1 or 0, depending on whether
091:             * wrt is this Variable or some other Variable.  This is not meant to be called directly.
092:             */
093:            public void compileDerivative(ExpressionProgram prog, int myIndex,
094:                    ExpressionProgram deriv, Variable wrt) {
095:                deriv.addConstant((wrt == this ) ? 1 : 0);
096:            }
097:
098:            /**
099:             * Check whether the value of this variable depends on the value of x.  This
100:             * is true if x is this Variable, false otherwise.
101:             */
102:            public boolean dependsOn(Variable x) {
103:                return this  == x;
104:            }
105:
106:            /**
107:             * Return a print string representing this variable.  The string is the
108:             * name of the variable, if it has one.  If not, the string "(unnamed variable)"
109:             */
110:            public String toString() {
111:                String s = getName();
112:                return (s == null) ? "(unnamed variable)" : s;
113:            }
114:
115:        } // end class Variable
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.