Homework 4 Python & Numerical Methods 21/22 September 27, 2021 Name the Colab notebook containing only the graded exercises: HW4 PNM21 s XXXXXXXXXXipynb (s1234567 = your s-number!) Share the notebook...

I would only like to see the codes per exercise, including some comments. There is no need for more additional text. I would also like for the homework to be graded with an 8 maybe, not 10 :). If that is not possible I will change stuff myself, no worries.


Homework 4 Python & Numerical Methods 21/22 September 27, 2021 Name the Colab notebook containing only the graded exercises: HW4 PNM21 s1234567.ipynb (s1234567 = your s-number!) Share the notebook with [email protected] Save and pin revision before sharing Do not open or alter the file before you received feedback Share as editor if you’d like to get feedback Deadline is Monday October 4, 11.00h Grading: You must hand in exactly three of the four exercises for maximum points. Each of these exercises is worth 4 points if your code runs correctly. The remaining 6 points per question are earned by writing concise, elegant and efficient code. Note: points can still be earned by reflecting on why the code does not run or work as expected. The grading will occur using the rubric that can be found on Nestor. Hint: If the output of your program is a line of printed text with a result of a computation included, you can use f-strings to display a variable in a string. Exercise 1 Remember the script you wrote some weeks ago that gives the (real) roots of the quadratic equation? Make it into a function f(a, b, c) that does the following: • plot the function y = ax2 + bx + c, • mark the zero(s) (if applicable) with a red dot, • label the axes and give the diagram a title that includes the function that is being graphed, • automatically adjust the range of the axes so that the intersection point(s) and the extreme point are visible. E.g. when f(1, 0,−1) is called we should see a parabola that intersects the x-axis at x1 = −1 and x2 = 1. See Figure 1 for an example of the output. Figure 1: Example output for Exercise 1. Exercise 2 Write a function that plots the different powers of xi for different values of i. The catch is, your program should be efficiently written so that all plots are changed by only changing one parameter. For example: Figure 2: Example output for Exercise 2 with i = 2. Figure 3: Example output for Exercise 2 with i = 5. The most efficient way of doing this is by using axes. To get a nice looking figure, you might even have to express the figure size in terms of the number of subfigures. • Label the axes of the subfigures. • Give each subfigure a title. • Give the figure an overall title. • Only one parameter has to be changed to produce the different plots. Exercise 3 It is time (pun intended) to use the quiver function! Use it to represent the hand-in time of your homework. Figure 4: What time did you hand in your homework? • Make sure your clock has two hands of different sizes. • Do not forget the rim of the clock, give it a nice color. • Give the “plot” a title. Do study the quiver documentation, to be found on the Matplotlib website. Exercise 4 Plot in 3D the field lines of an electron. In your plot, visualize the electron with a red dot in the center of a square box. We are not concerned with the details of the field strength, only about the visualisation (i.e. make sure that the vectors point in the right direction). • Give the figure an appropriate title. • Label the objects in the figure in a legend. • Less is more? Play with the amount of vectors in the graph. Figure 5: An example of what the output of exercise 4 could look like.
Sep 28, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here