Skip to content

Commit

Permalink
Added multiply method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Olcay Taner YILDIZ committed Apr 17, 2021
1 parent eac0c28 commit fb539f4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/Math/Vector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,24 @@ public class Vector : Equatable{
return result
}

/**
* The multiply method takes a {@link Vector} v as an input and creates new {@link Matrix} m of [size x size of input v].
* It loops through the the both values {@link ArrayList} and given vector's values {@link ArrayList}, then multiply
* each item with other with other items and puts to the new {@link Matrix} m.
- Parameters:
- v: Vector input.
- Returns: Matrix that has multiplication of two vectors.
*/
public func multiply(v: Vector) -> Matrix{
let m : Matrix = Matrix(row: __size, col: v.__size)
for i in 0..<__size{
for j in 0..<v.__size{
m.setValue(rowNo: i, colNo: j, value: values[i] * v.values[j])
}
}
return m
}

/**
The divide method takes a double value as an input and divides each item of values list with given value.

Expand Down

0 comments on commit fb539f4

Please sign in to comment.