Skip to content

Commit 1176ce3

Browse files
committed
Update README.md
1 parent c5e1efc commit 1176ce3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ archive that you can include into your project. PHP will autoload classes from i
2727

2828
## Usage
2929

30+
### Matrix
31+
3032
Start with a `use` statement for the class:
3133

3234
use MCordingley\LinearAlgebra\Matrix;
@@ -128,8 +130,47 @@ and U portions of the decompositions, respectively. The LUP decomposition additi
128130
`permutationArray` to fetch the P component of the decomposition as well as `parity` to return the total number of
129131
pivots performed.
130132

133+
### Vector
134+
135+
As with `Matrix`, import the class into your current namespace:
136+
137+
use MCordingley\LinearAlgebra\Vector;
138+
139+
Since a `Vector` is a special case of a `Matrix`, `Vector` inherits from `Matrix`. As such, every method available on
140+
`Matrix` is also available on `Vector`. `Vector` also exposes additional methods specific to working with vectors.
141+
142+
Creating a `Vector` differs from creating a `Matrix` only in that the constructor takes an array of scalars, rather
143+
than an array of arrays:
144+
145+
$vector = new Vector([1, 2, 3, 4]);
146+
147+
Note that `Vector` instances are all row vectors. If you need a column vector, `transpose()` the vector to get a
148+
`Matrix` with a single column.
149+
150+
If you need to cast a `Matrix` into a `Vector`, call the factory method `fromMatrix()`:
151+
152+
$vector = Vector::fromMatrix($matrix);
153+
154+
`toArray()` is overridden to return an array of scalars to mirror how the constructor works. It is equivalent to
155+
calling `$matrix->toArray()[0]` on a `Matrix` instance.
156+
157+
`getSize()` is provided as an alias for `getColumnCount()`. `sum()` will return the sum of the `Vector` elements,
158+
while `dotProduct($otherVector)` will return the sum of the pair-wise products of `$vector` and `$otherVector`,
159+
and is also availabe aliased as `innerProduct($otherVector)`. `outerProduct($otherVector)` will return a new Matrix
160+
representing the outer product of the two vectors. `crossProduct($otherVector)` is also available. Vectors may be
161+
normalized with `normalize()`. They may also be projected onto other vectors with `project($otherVector)`.
162+
163+
For measures of vector magnitude, `l1Norm()`, `l2Norm()`, and `maxNorm()` are all available, with `length()` as
164+
an aliax for `l2Norm()`.
165+
166+
Links to relevant Wikipedia articles are provided in the function documentation for additional detail.
167+
168+
131169
## Change-log
132170

171+
- 2.1.0
172+
- Add `Vector` as a subclass of `Matrix`. Thanks to battlecook for this contribution.
173+
133174
- 2.0.0
134175
- Drop support for PHP 5.x
135176
- Introduce strict scalar type hints

0 commit comments

Comments
 (0)