Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to write these Python and whats the problems with my code? 2l a) A particular inner-product of two 3-dimensional vectors is defined as -E3-E

How to write these Python and whats the problems with my code? image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
2l a) A particular inner-product of two 3-dimensional vectors is defined as -E3-E Create a function InnerProduct (x,y) that calculates the value of the above iner product, given two threedimensional vectors (2 Marks) x and y . In [2): def InnerProduct(x,y): dot (-x1) (y1)+(x2) (y2)+2 (x3) (y3) return dot 2/ b) Given a three-dimensional vector v, the unit vector i, with unit magnitude and which points in the same direction as v, is given by the following: Create a function Unitvector(vector) that converts a three-dimensional vector to a unit vector which points in the same direction. (2 Marks) In [13:import numpy as np vanp.array([vi,v2,v3]) magxanp.dot (v,v)* e.s print (magx) def Unitvector(vector): usmagv return u 1/ b) Create a function MultiplyByM(vector) which multiplies an arbitrary, three-dimensional vector vector by the matrix M shown below and gives the output as a vector in the form of an array 21 M- 2 12 4 3 6 -5 (2 Marks) In (6) def MultiplyByM(vector): nenp.cross(M,vector) numpy asnp array((1,2,-1,2,12,41,03,6,-) le "eipython-input-6-415fa9829c16" ine M-Onp.array([1,2,-1,02,12,41.13,6,-]) SyntaxError: invalid syntax Create a function Rowslice(array, n, m) (with arguments in that order) which slices out the n th and m th rows of array (where n and m start from 1 and m is greater than n ), so that (for example): RowSlice 4 5 6,3- (3 Marks) In def RowSlice(array,n,m): import numpy as np anp . array( [1,2,3][4,5,6],[7,8,9]) In PRE-CHECK CELL for 93/ assert "Rowslice" in dir), "you have not defined a funetion naned Rowslice,or you may not have executed your answer cell. import numpy as np mtestanp.array(t1,2,3,4,5],[3,4,5,6,71,(5,6,7,8,9]1) assert type (RowSlice(mtest,1,2))1stype(None), "Your function Rowslice does not return anything. assert type (Rowslice(ntest,1,2))np.ndarray, "Your function Rowslice does not return an array assert Rowslice(mtest,1,2).shape- (2,5), "Your funtion Rouslice does not return an array with the correct shape." print ("your answer to question 3/ passed the pre-checks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

2. Outline the functions of nonverbal communication

Answered: 1 week ago