Question: Write a program that lets a user enter two vectors, A and B, of arbitrary dimension. You should allow the user to first enter the
Write a program that lets a user enter two vectors, A and B, of arbitrary dimension. You should allow the user to first enter the dimension of the vector, then get the elements of the two vectors from the user. Then, you should output (in a clearly labeled way), the results of these computations:
The magnitude of vector A and the magnitude of vector B
A + B
A B
And the dot product (inner product) of A and B
from math import * dimension=int(input('Please input the dimension of vector')) vector_A=[dimension] vector_B=[dimension] count=1 directions='Please Enter on value at a time of vector when promted' while dimension>=2 and count<=dimension: print('Enter vector A',count) vector_1=int(input()) vector_A.append(vector_1) print('Enter vector B', count) vector_2 = int(input()) vector_B.append(vector_2) count = count + 1 dot=(vector_A[0]*vector_B[0]+vector_A[1]*vector_B[1]) mag_vecA=sqrt(vector_A[0]**2+vector_A[1]**2) mag_vecB=sqrt(vector_B[0]**2+vector_B[1]**2) vec_addx=str(vector_A[0]+vector_B[0]) vec_addy=str(vector_A[1]+vector_B[1]) vec_subx=str(vector_B[0]-vector_A[0]) vec_suby=str(vector_B[1]-vector_A[1]) print(dot) print(mag_vecA) print(mag_vecB) print('<',vec_addx,vec_addy,'>') print('<',vec_subx,vec_suby,'>') Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
