Moon Aufgabe
This commit is contained in:
1 parent
a9c95dfc03
commit
0c59c96407
3 files changed
+210
No files matched your search
+23
@@ -59,6 +59,29 @@ def matmul(matrix_a: Matrix, matrix_b: Matrix) -> Matrix:
|
||||
import math
|
||||
|
||||
|
||||
def matvec(a: Matrix, v: list[float]) -> list[float]:
|
||||
"""Return the product of a matrix and a column vector.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
a: list[list[float]]
|
||||
Matrix of shape ``(m, n)``.
|
||||
v: list[float]
|
||||
Column vector of shape ``(n,)``.
|
||||
|
||||
Returns
|
||||
-------
|
||||
list[float]
|
||||
Resulting vector of shape ``(m,)``.
|
||||
"""
|
||||
if not isinstance(a, list) or not isinstance(v, list):
|
||||
raise TypeError("Matrix and vector must be lists of numbers.")
|
||||
if not a or not a[0] or not v:
|
||||
raise ValueError("Matrix and vector must be non-empty.")
|
||||
if any(len(row) != len(v) for row in a):
|
||||
raise ValueError(f"Inner dimensions mismatch: vector has {len(v)} entries.")
|
||||
return [sum(x * y for x, y in zip(row, v)) for row in a]
|
||||
|
||||
def rot_2D(theta: float) -> Matrix:
|
||||
"""Return a 2×2 rotation matrix for the given angle ``theta``.
|
||||
|
||||
|
||||
Reference in new issue
Block a user