Question
Using Python as a Calculator a) Create the following variables : x, containing the value 0.37 y, containing the value 1.52 z, containing the value
Using Python as a Calculator a) Create the following variables : x, containing the value 0.37 y, containing the value 1.52 z, containing the value 3 s, containing the value hello i) Find the type of each variable. Why are some different? ii) For each of the following expressions, compute them, assign them to a variable (you chose the name), and then print their values to the console.
3x 2y + z
x^y /z + z/x
x^2 + y^2 4z^3
b) For each of the following mathematical expressions, compute them, assign them to a variable (you chose the name), and then print their values to the console.
3^15
sin(2/3)
ln( 12/ 7 )
tan(e^5.6 )
arccos(0.3) (in radians)
arccos(0.3) (in degrees)
2) Vectors in Python a) Using the numpy.array constructor, create variables containing the following 4-dimensional vectors.
u, containing the vector[1.3,8.3,-2.3,4.6]
v,containing the vector[2.4,0.3,0.0,-2.1]
w,containing the vector[1.0,1.0,1.0,1.0]
i) Calculate and print out the following :
3u + 2v 6w
u v
u w
ii) Compute the sum of all of the components of v, by indexing the individual components (i.e. using v[0], v[1], etc ). Print out this result.
iii) Compute and print out the sum of the first and last components of v, using indexing. Create a 4-dimensional vector q such that q w computes the same quantity.
iv) Compute ||u||, the norm of the vector u, using indexing. I.e. , compute the square root of the sum of the squares of the components of u, where you use u[0], u[1], etc to access the individual components of u. Compute ||u|| by computing the square root of the dot product of u with itself, and verify that you get the same result. Compute ||u|| by using the numpy.linalg.norm function, and verify that you get the same result.
v) Compute the angle between the vectors u and v (in degrees), and the angle between the vectors v and w (in degrees)
3) Creating vectors using numpy.zeros a) Create a variable containing a vector of length 6 that is all zeros, using the numpy.zeros function.
b) Create a variable p containing the vector[5,0,0,0,3,-2]by first creating an all-zero vector, and then assigning the individual components, using the syntax p[0] = 5 ... etc c) Create a variable q that is a vector of length 6 that is all zeros, except for component 5 ( 4 using zero-based indexing). Confirm that q p is equal to p[4]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started