Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3 problems to solve in jupyter python. it relates to programming and maths. DO NOT USE any file compression method. While the tasks below mention
3 problems to solve in jupyter python. it relates to programming and maths.
DO NOT USE any file compression method. While the tasks below mention magnetic fields and particle orbits, you do not need to know any physics to do this test, which only examines your Python programming skills. Problem 1 (15 marks): Reading and plotting data from a file. Read in the contents of the file 'rev26_27.dat' into a RecArray. This is a data file containing a spacecraft called Cassini's magnetometer measurements from two orbits around Saturn in 2007. The columns are day-of-year since 2004, and three field components in spherical polar coordinates (B, Bo, B.). Make following plot: Plot using red pixel points B, versus day of year since 2004. Limit the time (date) axis to between 940 to 950 days, and the y axis to between -3 to 4 Label the axes appropriately and add a title and a legend. Add a dotted green horizontal line at B, = 0 Finally, plot a linear regression (line of best linear fit) in blue, and print the coefficients of the fit. In [177]: #Answer Problem 2 (25 marks): Plot a color map and a contour plot of a function, and a histogram Here we want to define a function z of x and y coordinates: sin Ax cos(y + r) ZE B+x where r = x2 + y2 A and B are constants. We then plot the function with a colour map and make a histogram giving some details about the map. In particular, please do the following: Introduce a Python function that does the following: (1) defines Numpy arrays x and y from a to b with N elements each; (2) computes the values of the function z as defined above; (3) accepts N, a and b as arguments and A and B as keywords with default values A = 1, B = 0; (4) return arrays x, y and the 2D Numpy array z. Produce a figure with two panels side by side horisontally. The left hand side panel should show the colour map image and a contour plot (on the same image) of function z for A = 1, B=1, N = 100. a = 0, b = 21. The right hand panel should show the histogram of the values of z for all the (N XN) pixels. Make sure that you plot looks professional, e.g., has labels and the title. Test that your code works for B between 0 and 2. Compute and print in one line the mean of the function z(x, y) on the domain defined above. Use .format statement and the scientific notation with 4 digits after the floating point. En [179]: #Answer Problem 3 (OPTIONAL, 10 marks): Using Runge-Kutta method to integrate an ODE In Section 9 of the course we learned how to integrate Ordinary Differential Equations. Use the examples given in Sec09_ODES_2021_Updated where we integrate a particle orbit around the Earth. This time, The initial conditions are xo = -5 x 10 m, yo = 0, 0x0 = 0, 0,0 = -300 The equation for the force is now slightly different: F, = Gm (1 + riro) V mer where m is the mass of the Earth, and ro = 4 x 108 m. Integrate the orbit for 10 seconds using the Runge-Kutta method with 10% points. Plot the orbit. En [178]: #Your Answer here: DO NOT USE any file compression method. While the tasks below mention magnetic fields and particle orbits, you do not need to know any physics to do this test, which only examines your Python programming skills. Problem 1 (15 marks): Reading and plotting data from a file. Read in the contents of the file 'rev26_27.dat' into a RecArray. This is a data file containing a spacecraft called Cassini's magnetometer measurements from two orbits around Saturn in 2007. The columns are day-of-year since 2004, and three field components in spherical polar coordinates (B, Bo, B.). Make following plot: Plot using red pixel points B, versus day of year since 2004. Limit the time (date) axis to between 940 to 950 days, and the y axis to between -3 to 4 Label the axes appropriately and add a title and a legend. Add a dotted green horizontal line at B, = 0 Finally, plot a linear regression (line of best linear fit) in blue, and print the coefficients of the fit. In [177]: #Answer Problem 2 (25 marks): Plot a color map and a contour plot of a function, and a histogram Here we want to define a function z of x and y coordinates: sin Ax cos(y + r) ZE B+x where r = x2 + y2 A and B are constants. We then plot the function with a colour map and make a histogram giving some details about the map. In particular, please do the following: Introduce a Python function that does the following: (1) defines Numpy arrays x and y from a to b with N elements each; (2) computes the values of the function z as defined above; (3) accepts N, a and b as arguments and A and B as keywords with default values A = 1, B = 0; (4) return arrays x, y and the 2D Numpy array z. Produce a figure with two panels side by side horisontally. The left hand side panel should show the colour map image and a contour plot (on the same image) of function z for A = 1, B=1, N = 100. a = 0, b = 21. The right hand panel should show the histogram of the values of z for all the (N XN) pixels. Make sure that you plot looks professional, e.g., has labels and the title. Test that your code works for B between 0 and 2. Compute and print in one line the mean of the function z(x, y) on the domain defined above. Use .format statement and the scientific notation with 4 digits after the floating point. En [179]: #Answer Problem 3 (OPTIONAL, 10 marks): Using Runge-Kutta method to integrate an ODE In Section 9 of the course we learned how to integrate Ordinary Differential Equations. Use the examples given in Sec09_ODES_2021_Updated where we integrate a particle orbit around the Earth. This time, The initial conditions are xo = -5 x 10 m, yo = 0, 0x0 = 0, 0,0 = -300 The equation for the force is now slightly different: F, = Gm (1 + riro) V mer where m is the mass of the Earth, and ro = 4 x 108 m. Integrate the orbit for 10 seconds using the Runge-Kutta method with 10% points. Plot the orbit. En [178]: #Your Answer hereStep 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