Docsity

Python Programming Problem Set, Assignments of Computer Programming

Partial preview of the text

Download Python Programming Problem Set and more Assignments Computer Programming in PDF only on Docsity!

4. A normal matrix is defined as AA* = A* A, where * denotes the conjugate transpose (or adjoint) of a matrix. Define a function that checks whether a real matrix is normal or not. Show that the following matrix is normal. 110 A=]0 1 1 101 2. Write a code to create an array for a tensor ML, with elements mjj, = i * j * k, where i, j,k € [0, 1,2], using a for...in loop. What is the dimension and shape of M? Find the matrix which corresponds to a) i = O,b) j = 1, andc) k = 2 o A Hermitian matrix is defined as A = A*, where * denotes the conjugate transpose (or adjoint) of a matrix. Create a random matrix A and explicitly show that A + A* is both normal and Hermitian. 4. Consider the harmonic oscillator. The equation of motion for the harmonic oscillator is ax 2 = +ex=0. dt? dx p dp 2 This can be written as a pair of first order ODEs, namely —— = — and — = —mo"x dt m dt Representing, dx/dt = Ax/At and dp/dt = Ap/At, as small changes in x and p with change in time, ¢. Write a function that finds x + Ax and p+ Ap, for any given value of x, p, and At. You can take = 2/5 andm = 1.0. For time t = Q tot = 10, in time-steps of At = 1075, using matplotlib i) plot the functions x and p with time. You can take the initial values as Xp = Po = 0 li) plot x vs p to get the trajectory of a simple harmonic oscillator in the phase space. a . Define a function that calculates the trace and determinant of a 2 x 2 matrix A, and returns a tuple at the output, i.e., output is (Tr( A), det(A)).