[Solved] CTA200H 2018 Problem Set 1

$25

File Name: CTA200H_2018_Problem_Set_1.zip
File Size: 244.92 KB

SKU: [Solved] CTA200H 2018 Problem Set 1 Category: Tag:
5/5 - (1 vote)

Please submit your responses electronically by github. Instructions included at the bottom of this assignment. Make sure the instructors will be able to run your code. Also include any figures you make as part of the activity.

For this assignment you may work in pairs and submit your work as a pair. In this case please make sure to discuss as much as possible and to share the coding work equitably.

  1. (Dan Green.) Write a script that finds and replaces a given word in all the .txt files in the working directory, with the following properties:
    • The script name is called with name find replace where find and replace are words the user chooses when running the program. b A new directory named replace is created within the working directory.

c A copy of the .txt files with find is put in the replace directory, but with all occurrences of find replaced by replace. If a file does not contain find, it is ignored.

  1. (Adapted from Newman.) The binomial coefficient is given by

(1)

for k 1 and 1 for

  • Write your own routine to generate the binomial coefficients for a givenn and k. Make sure the result is an integer (not a float) and gives the (correct) value 1 for k = 0. (Hint; you can do a cancellation to make it more tractable.)
  • Use your routine to write out the first 20 lines of Pascals triangle. Thisgives the coefficients for expanding binomials of the form (x + y)n.
  • Consider a biased (e.g., bent) coin with probability p of coming up heads, and probability 1 p of coming up tails. The probability of obtaining heads k times when flipping the coin n times is given by

. (2)

Consider an experiment in which you flip the coin n times and hope to obtain at least k values of heads. For values of p, n, and k of your choice, use your routine to calculate the probability of obtaining heads at least k times in n flips. (Example application: a baseball player with batting average p = 0.250 has n = 4 attempts to obtain a hit, or at-bats, during a given game. What is the chance that s/he will obtain at least one hit during the game, assuming that all at-bats are statistically the same and uncorrelated?)

  • Simulate the experiment N times for N {10,100,1000}, or a similar range of your choice. For each value of N, which fraction of experiments were successful? Consider showing the results in a plot.
  1. (Adapted from Newman.) The Bessel function of the first kind of order m is given by

. (3)

  • Write a routine to calculate this integral directly, using the methodof integration of your choice, using only the library sine and cosine functions (you may use the library Bessel functions to check the results of your integral). Plot the results for a few values of m.
  • Suppose that light passing through a circular telescope aperture of ra-dius a is focussed on the telescopes focal plane. If the source is effectively a point on the sky, then the pattern of intensity seen in the focal plane at a distance q from the optical axis is given by

(4)

where I0 is the intensity at the center, and x = 2Raq. Here is the wavelength of the light and R is the distance from the aperture to the focal plane. This is known as the point spread function in optical astronomy, the beam in radio astronomy, and the Airy disk in general. (The geometrical ratio R/(2a) is known as the f-number of the telescope and typically has values of several.) For a given set of parameters, make an image of the two-dimensional point spread function, using a monochrome color scheme. Indicate the x and y axes with real distance units. (It might be hard to see the detail away from the main beam; if so, try increasing the contrast of your image in order to see the features on the edge.)

  • Download a high-resolution astronomical (or other) image of your choice.If this image were viewed through a telescope with a finite aperture, each pixels value would get smeared out to neighboring pixels, degrading the image. This is known as convolution. To simulate how this image would look when viewed through a telescope, use a canned convolution routine (e.g., scipy.ndimage.filters.convolve(), scipy.signal.convolve2d()) to convolve the image by your point-spread function. Dont worry about being quantitative in this sub-section; rather play around to see what happens to your image when you convolve it.
  1. (George) Scene: Its 3pm and your supervisor has just handed you their old Fortran77 code that they swear solved this problem in the 80s and is really smartly written and easy to follow. After the meeting you take one look at the code and realize it doesnt. And its not.

But, you said youd have results by the group meeting the following day, so lets see if we can understand what it is doing, fix it up, and get some results! Also, this code has somehow already been converted into python 3. who knows

The code can be found in the form of a jupyter notebook in problemset1/question6/question6.ipynb . Go through the examples near the top, and fix up the code in the final cell.

  1. For each point in the complex plane c = x + iy, with 2 < x < 2 and 2 < y < 2, set z0 = 0 and iterate the equation zi+1 = zi2 + c. Note what happens to the zis: some points will remain bounded in absolute value |z|2 = (z)2 + (z)2, while others will run off to infinity. Make an image in which your points c that diverge are given one color and those that stay bounded are given another. (Once you have done this, you can try coloring the points that diverge using a colorscale that indicates the iteration number at which the given point diverged.) Try zooming in on a portion of the image and trying again.
  2. Write your own program simulating a space battle. It should have 3 typesof spaceships: standard spaceships, warships, and speeders. Each ship has lasers, shields and hull strength (and most importantly, a name!). Warships additionally have high powered missiles which they fire 30% of the time, while speeders have a 50% chance to dodge incoming shots. When a spaceship is shot by another ship, it first depletes its shields equal to the strength of the shot. When it runs out of shields, it takes hull damage at 50% of the shot strength. Once the hull is breached, the ship is destroyed!

Your program should include a class Ship that defines the standard spaceship, and two classes which inherit from Ship called Warship and Speeder. The classes should store the ships shield strength, hull strength, laser power and name. There should be, at a minimum, methods to deal with when a ship shoots, is shot at, whether the ship is destroyed or not, and printing a diagnostic summary of the ships status.

Your program should instantiate 3 regular ships, 1 warship and 1 speeder.

The spaceships should shoot randomly at each other until only one remains (targets cannot be themselves nor ships that are already destroyed). Print a log of the battle as it progresses, and declare a final victor.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CTA200H 2018 Problem Set 1
$25