CS29006 Assignment 1 Solved

25.00 $

Category:

Description

5/5 - (1 vote)

We provide an implementation of a Vector class in the attached file Vector.py, representing the coordinates of a vector in a multidimensional space. For example, in a three-dimensional space, we might wish to represent a vector with coordinates 5, −2, 3 . Although it might be tempting to directly use a Python list to represent those coordinates, a list does not provide an appropriate abstraction for a geometric vector. In particular, if using lists, the expression [5, −2, 3] + [1, 4, 2] results in the list [5, −2, 3, 1, 4, 2]. When working with vectors, if u = 5, −2, 3 and v = 1, 4, 2 , one would expect the expression, u + v, to return a three-dimensional vector with coordinates 6, 2, 5.

We therefore try to define a Vector class, in Vector.py, that provides a better abstraction for the notion of a geometric vector. Internally, our vector should rely upon an instance of a list, named _coords, as its storage mechanism. By keeping the internal list encapsulated, we should be able to enforce the desired public interface for instances of our class.
In Vector.py, you need to define the following magic functions which should work as specified below:
Question 1.
a) [1 Mark] __len__(self) :This function should be able return the dimension of the vector
b) [1 Mark] __getitem_(self,j) : Function should be able return the jth coordinate of the vector
c) [1 Mark] __setitem__(self,j,val) : Function should be able to set the jth coordinate of vector to val
Example : If two vectors are u =[5, -2, 3] and v = [1, 4, 2] then, output of u + v =
[6,2,5]
Question 2.
Question 4.
Question 5.
Question 6.
Question 7.

  • AssignmentQs1-m8myyt.zip