Source Code Cross Referenced for RationalFunction.java in  » Science » jscience-4.3.1 » org » jscience » mathematics » function » 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 » jscience 4.3.1 » org.jscience.mathematics.function 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
003:         * Copyright (C) 2006 - JScience (http://jscience.org/)
004:         * All rights reserved.
005:         * 
006:         * Permission to use, copy, modify, and distribute this software is
007:         * freely granted, provided that this notice is preserved.
008:         */
009:        package org.jscience.mathematics.function;
010:
011:        import java.util.List;
012:        import org.jscience.mathematics.structure.Field;
013:
014:        import javolution.context.ObjectFactory;
015:        import javolution.text.Text;
016:        import javolution.text.TextBuilder;
017:
018:        /**
019:         * This class represents the quotient of two {@link Polynomial}, 
020:         * it is also a {@link Field field} (invertible). 
021:         * 
022:         * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
023:         * @version 3.1, April 1, 2006
024:         */
025:        public class RationalFunction<F extends Field<F>> extends
026:                Function<F, F> implements  Field<RationalFunction<F>> {
027:
028:            /**
029:             * Holds the factory for rational functions.
030:             */
031:            /**
032:             * Holds the dividend.
033:             */
034:            private Polynomial<F> _dividend;
035:
036:            /**
037:             * Holds the divisor.
038:             */
039:            private Polynomial<F> _divisor;
040:
041:            /**
042:             * Default constructor.
043:             */
044:            private RationalFunction() {
045:            }
046:
047:            /**
048:             * Returns the dividend of this rational function.
049:             * 
050:             * @return this rational function dividend. 
051:             */
052:            public Polynomial<F> getDividend() {
053:                return _dividend;
054:            }
055:
056:            /**
057:             * Returns the divisor of this rational function.
058:             * 
059:             * @return this rational function divisor.
060:             */
061:            public Polynomial<F> getDivisor() {
062:                return _divisor;
063:            }
064:
065:            /**
066:             * Returns the rational function from the specified dividend and divisor.
067:             * 
068:             * @param dividend the dividend value.
069:             * @param divisor the divisor value.
070:             * @return <code>dividend / divisor</code>
071:             */
072:            @SuppressWarnings("unchecked")
073:            public static <F extends Field<F>> RationalFunction<F> valueOf(
074:                    Polynomial<F> dividend, Polynomial<F> divisor) {
075:                RationalFunction<F> rf = FACTORY.object();
076:                rf._dividend = dividend;
077:                rf._divisor = divisor;
078:                return rf;
079:            }
080:
081:            @SuppressWarnings("unchecked")
082:            private static final ObjectFactory<RationalFunction> FACTORY = new ObjectFactory<RationalFunction>() {
083:
084:                protected RationalFunction create() {
085:                    return new RationalFunction();
086:                }
087:
088:                @SuppressWarnings("unchecked")
089:                protected void cleanup(RationalFunction rf) {
090:                    rf._dividend = null;
091:                    rf._divisor = null;
092:                }
093:            };
094:
095:            /**
096:             * Returns the sum of two rational functions.
097:             * 
098:             * @param that the rational function being added.
099:             * @return <code>this + that</code>
100:             */
101:            public RationalFunction<F> plus(RationalFunction<F> that) {
102:                return valueOf(this ._dividend.times(that._divisor).plus(
103:                        this ._divisor.times(that._dividend)), this ._divisor
104:                        .times(that._divisor));
105:            }
106:
107:            /**
108:             * Returns the opposite of this rational function.
109:             * 
110:             * @return <code>- this</code>
111:             */
112:            public RationalFunction<F> opposite() {
113:                return valueOf(_dividend.opposite(), _divisor);
114:            }
115:
116:            /**
117:             * Returns the difference of two rational functions.
118:             * 
119:             * @param that the rational function being subtracted.
120:             * @return <code>this - that</code>
121:             */
122:            public RationalFunction<F> minus(RationalFunction<F> that) {
123:                return this .plus(that.opposite());
124:            }
125:
126:            /**
127:             * Returns the product of two rational functions.
128:             * 
129:             * @param that the rational function multiplier.
130:             * @return <code>this ยท that</code>
131:             */
132:            public RationalFunction<F> times(RationalFunction<F> that) {
133:                return valueOf(this ._dividend.times(that._dividend),
134:                        this ._divisor.times(that._divisor));
135:            }
136:
137:            /**
138:             * Returns the inverse of this rational function.
139:             * 
140:             * @return <code>1 / this</code>
141:             */
142:            public RationalFunction<F> inverse() {
143:                return valueOf(_divisor, _dividend);
144:            }
145:
146:            /**
147:             * Returns the quotient of two rational functions.
148:             * 
149:             * @param that the rational function divisor.
150:             * @return <code>this / that</code>
151:             */
152:            public RationalFunction<F> divide(RationalFunction<F> that) {
153:                return this .times(that.inverse());
154:            }
155:
156:            @SuppressWarnings("unchecked")
157:            @Override
158:            public List<Variable<F>> getVariables() {
159:                return merge(_dividend.getVariables(), _divisor.getVariables());
160:            }
161:
162:            @SuppressWarnings("unchecked")
163:            @Override
164:            public F evaluate() {
165:                return _dividend.evaluate()
166:                        .times(_divisor.evaluate().inverse());
167:            }
168:
169:            @Override
170:            public Text toText() {
171:                TextBuilder tb = TextBuilder.newInstance();
172:                tb.append('(');
173:                tb.append(_dividend);
174:                tb.append(")/(");
175:                tb.append(_divisor);
176:                tb.append(')');
177:                return tb.toText();
178:            }
179:
180:            @Override
181:            public boolean equals(Object obj) {
182:                if (obj instanceof  RationalFunction) {
183:                    RationalFunction<?> that = (RationalFunction<?>) obj;
184:                    return this ._dividend.equals(this ._dividend)
185:                            && this ._divisor.equals(that._divisor);
186:                } else {
187:                    return false;
188:                }
189:            }
190:
191:            @Override
192:            public int hashCode() {
193:                return _dividend.hashCode() - _divisor.hashCode();
194:            }
195:
196:            //////////////////////////////////////////////////////////////////////
197:            // Overrides parent method potentially returning rational functions //
198:            //////////////////////////////////////////////////////////////////////
199:
200:            @Override
201:            public RationalFunction<F> differentiate(Variable<F> v) {
202:                return valueOf(_divisor.times(_dividend.differentiate(v)).plus(
203:                        _dividend.times(_divisor.differentiate(v)).opposite()),
204:                        _dividend.pow(2));
205:            }
206:
207:            @SuppressWarnings("unchecked")
208:            @Override
209:            public Function<F, F> plus(Function<F, F> that) {
210:                return (that instanceof  RationalFunction) ? this 
211:                        .plus((RationalFunction<F>) that) : super .plus(that);
212:            }
213:
214:            @SuppressWarnings("unchecked")
215:            @Override
216:            public Function<F, F> minus(Function<F, F> that) {
217:                return (that instanceof  RationalFunction) ? this 
218:                        .minus((RationalFunction<F>) that) : super .minus(that);
219:            }
220:
221:            @SuppressWarnings("unchecked")
222:            @Override
223:            public Function<F, F> times(Function<F, F> that) {
224:                return (that instanceof  RationalFunction) ? this 
225:                        .times((RationalFunction<F>) that) : super .times(that);
226:            }
227:
228:            @SuppressWarnings("unchecked")
229:            @Override
230:            public Function<F, F> divide(Function<F, F> that) {
231:                return (that instanceof  RationalFunction) ? this 
232:                        .divide((RationalFunction<F>) that) : super 
233:                        .divide(that);
234:            }
235:
236:            @SuppressWarnings("unchecked")
237:            @Override
238:            public RationalFunction<F> pow(int n) {
239:                return (RationalFunction<F>) super .pow(n);
240:            }
241:
242:            /**
243:             * Returns a copy of this rational function. 
244:             * {@link javolution.context.AllocatorContext allocated} 
245:             * by the calling thread (possibly on the stack).
246:             *     
247:             * @return an identical and independant copy of this rational function.
248:             */
249:            public RationalFunction<F> copy() {
250:                return RationalFunction.valueOf(_dividend.copy(), _divisor
251:                        .copy());
252:            }
253:
254:            private static final long serialVersionUID = 1L;
255:
256:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.