Vector Spaces

Vector Spaces

In mathematics, a vector space, also known as a linear space, is a mathematical structure that consists of a set of vectors along with operations of vector addition and scalar multiplication. Vector spaces are fundamental in linear algebra and have wide applications in various areas of mathematics, physics, computer science, and engineering.

Here are the key properties and characteristics of vector spaces:

  1. Closure under Addition: For any two vectors u and v in the vector space, their sum u + v is also in the vector space.
  2. Closure under Scalar Multiplication: For any vector u in the vector space and any scalar (real or complex) c, the scalar multiple c * u is also in the vector space.
  3. Associativity of Vector Addition: Vector addition is associative, meaning (u + v) + w = u + (v + w) for any vectors u, v, and w in the vector space.
  4. Commutativity of Vector Addition: Vector addition is commutative, meaning u + v = v + u for any vectors u and v in the vector space.
  5. Identity Element of Vector Addition: There exists a special vector called the zero vector, denoted as 0, which when added to any vector u, yields u itself. In other words, u + 0 = u for any vector u in the vector space.
  6. Inverse Element of Vector Addition: For every vector u in the vector space, there exists a vector -u (the additive inverse of u) such that u + (-u) = 0.
  7. Distributivity of Scalar Multiplication over Vector Addition: Scalar multiplication distributes over vector addition, meaning c * (u + v) = c * u + c * v for any scalar c and vectors u, v in the vector space.
  8. Distributivity of Scalar Multiplication over Scalar Addition: Scalar multiplication distributes over scalar addition, meaning (c + d) * u = c * u + d * u for any scalars c, d and vector u in the vector space.
  9. Compatibility of Scalar Multiplication with Field Multiplication: Scalar multiplication is compatible with field multiplication, meaning (c * d) * u = c * (d * u) for any scalars c, d and vector u in the vector space.

These properties ensure that vector spaces are well-behaved and have consistent algebraic structures. Examples of vector spaces include Euclidean spaces (such as 2D and 3D Cartesian spaces), function spaces, polynomial spaces, and more.


class Vector:
? ? def __init__(self, values):
? ? ? ? self.values = values


? ? def __add__(self, other):
? ? ? ? if isinstance(other, Vector) and len(self.values) == len(other.values):
? ? ? ? ? ? new_values = [x + y for x, y in zip(self.values, other.values)]
? ? ? ? ? ? return Vector(new_values)
? ? ? ? else:
? ? ? ? ? ? raise ValueError("Vector addition is only defined for vectors of the same length.")


? ? def __mul__(self, scalar):
? ? ? ? if isinstance(scalar, (int, float)):
? ? ? ? ? ? new_values = [scalar * x for x in self.values]
? ? ? ? ? ? return Vector(new_values)
? ? ? ? else:
? ? ? ? ? ? raise ValueError("Scalar multiplication is only defined for numeric scalars.")


? ? def __str__(self):
? ? ? ? return str(self.values)




# Example usage
v1 = Vector([1, 2, 3])
v2 = Vector([4, 5, 6])


# Vector addition
v3 = v1 + v2
print("Vector addition:", v3)


# Scalar multiplication
scalar = 2
v4 = v1 * scalar
print("Scalar multiplication:", v4)        


要查看或添加评论,请登录

Yeshwanth Nagaraj的更多文章

社区洞察

其他会员也浏览了