Source Code Cross Referenced for AbstractDoubleVector.java in  » Science » JSci » JSci » maths » vectors » 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 » JSci » JSci.maths.vectors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package JSci.maths.vectors;
002:
003:        import JSci.GlobalSettings;
004:        import JSci.maths.ExtraMath;
005:        import JSci.maths.Mapping;
006:        import JSci.maths.algebras.*;
007:        import JSci.maths.fields.*;
008:        import JSci.maths.groups.AbelianGroup;
009:
010:        /**
011:         * The AbstractDoubleVector class encapsulates vectors containing doubles.
012:         * @version 1.0
013:         * @author Mark Hale
014:         */
015:        public abstract class AbstractDoubleVector extends MathVector implements 
016:                BanachSpace.Member {
017:            protected AbstractDoubleVector(final int dim) {
018:                super (dim);
019:            }
020:
021:            /**
022:             * Compares two double vectors for equality.
023:             * Two vectors are considered to be equal if the norm of their difference is within the zero tolerance.
024:             * @param obj a double vector
025:             */
026:            public final boolean equals(Object obj) {
027:                return equals(obj, GlobalSettings.ZERO_TOL);
028:            }
029:
030:            public boolean equals(Object obj, double tol) {
031:                if (obj != null && (obj instanceof  AbstractDoubleVector)) {
032:                    final AbstractDoubleVector vec = (AbstractDoubleVector) obj;
033:                    return (this .dimension() == vec.dimension() && this 
034:                            .subtract(vec).norm() <= tol);
035:                } else
036:                    return false;
037:            }
038:
039:            /**
040:             * Returns a comma delimited string representing the value of this vector.
041:             */
042:            public String toString() {
043:                final StringBuffer buf = new StringBuffer(8 * N);
044:                int i;
045:                for (i = 0; i < N - 1; i++) {
046:                    buf.append(getComponent(i));
047:                    buf.append(',');
048:                }
049:                buf.append(getComponent(i));
050:                return buf.toString();
051:            }
052:
053:            /**
054:             * Returns a hashcode for this vector.
055:             */
056:            public int hashCode() {
057:                return (int) Math.exp(norm());
058:            }
059:
060:            /**
061:             * Returns a component of this vector.
062:             * @param n index of the vector component.
063:             * @exception VectorDimensionException If attempting to access an invalid component.
064:             */
065:            public abstract double getComponent(int n);
066:
067:            /**
068:             * Sets the value of a component of this vector.
069:             * @param n index of the vector component.
070:             * @param x a number.
071:             * @exception VectorDimensionException If attempting to access an invalid component.
072:             */
073:            public abstract void setComponent(int n, double x);
074:
075:            public Object getSet() {
076:                throw new RuntimeException("Not implemented: file bug");
077:            }
078:
079:            /**
080:             * Returns the l<sup>n</sup>-norm.
081:             * @jsci.planetmath VectorPnorm
082:             */
083:            public double norm(int n) {
084:                double answer = Math.pow(Math.abs(getComponent(0)), n);
085:                for (int i = 1; i < N; i++)
086:                    answer += Math.pow(Math.abs(getComponent(i)), n);
087:                return Math.pow(answer, 1.0 / n);
088:            }
089:
090:            /**
091:             * Returns the l<sup>2</sup>-norm (magnitude).
092:             * @jsci.planetmath VectorPnorm
093:             */
094:            public double norm() {
095:                double answer = getComponent(0);
096:                for (int i = 1; i < N; i++)
097:                    answer = ExtraMath.hypot(answer, getComponent(i));
098:                return answer;
099:            }
100:
101:            /**
102:             * Returns the l<sup><img border=0 alt="infinity" src="doc-files/infinity.gif"></sup>-norm.
103:             * @author Taber Smith
104:             * @jsci.planetmath VectorPnorm
105:             */
106:            public double infNorm() {
107:                double infNorm = Math.abs(getComponent(0));
108:                for (int i = 1; i < N; i++) {
109:                    final double abs = Math.abs(getComponent(i));
110:                    if (abs > infNorm)
111:                        infNorm = abs;
112:                }
113:                return infNorm;
114:            }
115:
116:            /**
117:             * Returns the mass (l<sup>1</sup>-norm).
118:             */
119:            public double mass() {
120:                double mass = 0.0;
121:                for (int i = 1; i < N; i++)
122:                    mass += getComponent(i);
123:                return mass;
124:            }
125:
126:            //============
127:            // OPERATIONS
128:            //============
129:
130:            /**
131:             * Returns the addition of this vector and another.
132:             * @param v a double vector.
133:             * @exception VectorDimensionException If the vectors are different sizes.
134:             */
135:            public abstract AbstractDoubleVector add(AbstractDoubleVector v);
136:
137:            /**
138:             * Returns the subtraction of this vector by another.
139:             * @param v a double vector.
140:             * @exception VectorDimensionException If the vectors are different sizes.
141:             */
142:            public abstract AbstractDoubleVector subtract(AbstractDoubleVector v);
143:
144:            /**
145:             * Returns the multiplication of this vector by a scalar.
146:             * @param x a double.
147:             */
148:            public abstract AbstractDoubleVector scalarMultiply(double x);
149:
150:            /**
151:             * Returns the division of this vector by a scalar.
152:             * @param x a double.
153:             * @exception ArithmeticException If divide by zero.
154:             */
155:            public abstract AbstractDoubleVector scalarDivide(double x);
156:
157:            /**
158:             * Returns a normalised vector (a vector with norm equal to one).
159:             */
160:            public AbstractDoubleVector normalize() {
161:                return this .scalarDivide(norm());
162:            }
163:
164:            /**
165:             * Returns the scalar product of this vector and another.
166:             * @param v a double vector.
167:             * @exception VectorDimensionException If the vectors are different sizes.
168:             */
169:            public abstract double scalarProduct(AbstractDoubleVector v);
170:
171:            /**
172:             * Applies a function on all the vector components.
173:             * @param f a user-defined function.
174:             * @return a double vector.
175:             */
176:            public abstract AbstractDoubleVector mapComponents(final Mapping f);
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.