hree-dimensional, with default value  equal to <0,0,0>. The + operator can be used between two vectors in order to perform vector addition. The * operator can be used between a vector and a number in order to perform vector scalar multiplication. Using print() on a vector will print its component values. See example below. The Vector class has a method cross_product() where a.cross_product(b) performs a cross product between vectors a and b and returns the resulting vector. The Vector class has a method dot_product() where a.dot_product(b) performs a dot product between vectors a and b and returns the resulting value. The Vector class has a method magnitude() where a.magnitude() returns the magnitude of vector a. You may use the math module for this exercise and nothing else. Example usage

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Create a module vector in a file called vector.py. The module contains the class Vector which has the following properties:

  • The vector is three-dimensional, with default value <x,y,z> equal to <0,0,0>.
  • The + operator can be used between two vectors in order to perform vector addition.
  • The * operator can be used between a vector and a number in order to perform vector scalar multiplication.
  • Using print() on a vector will print its component values. See example below.
  • The Vector class has a method cross_product() where a.cross_product(b) performs a cross product between vectors a and b and returns the resulting vector.
  • The Vector class has a method dot_product() where a.dot_product(b) performs a dot product between vectors a and b and returns the resulting value.
  • The Vector class has a method magnitude() where a.magnitude() returns the magnitude of vector a.

You may use the math module for this exercise and nothing else.

Example usage

 
from vector import Vector
 
v1 = Vector(1, 1, 0) # Initialize vector <1,1,0>
v2 = Vector(2, 1, 3) # Initialize vector <2,1,3>
 
print(v1) # Should print "<1,1,0>"
print(v2) # Should print "<2,1,3>"
 
v3 = v1 + v2 # v3 is <3,2,3>
v4 = v1 * 3 # v4 is <3,3,0>
v5 = v2 * 2 # v5 is <4,2,6>
 
v1.cross_product(v2) # returns <3,-3,-1>
v1.dot_product(v2) # returns 3
v1.magnitude() # returns 1.4142135623730951
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY