Physics 222 Assignment 4

Due February 21


Please turn in this assignment (and all future assignments for this course) by emailing them to me . Please use the subject of "Physics 222 HW4" for these assignments (if you use the link above, the subject will be added automatically). Please attach the source code to any programs that you write for this assignment. If you write more than one program, attach each separately. When answering the questions themselves feel free to answer directly in the body of your message (or attach your answers). I may take off points for assignments that are not sent to me in the correct form.

  1. Number Checker

    Write a program that will use a separate function to calculate all of the following quantities for a given integer:

    1. Whether the number is prime or not. For the purpose of this assignment consider numbers to be prime if their absolute value is prime.
    2. The number's greatest factor (other than itself).
    3. Whether the sum of the digits of the number is odd or even.
    4. What the square root of the number is.

    Your program should prompt the user for an integer, and then pass your integer to all of the functions that determine the properties of your numbers.

    Feel free to reuse your prime number code, but beware that you will have to take care of cases such as 0, 1, and negative numbers.

    Show your results when using the following numbers as input: -143, 53, 0, -13459, 457, 77779, -1, and 17.

  2. Heat Conduction Through a Window

    In this problem you will write a program to find the steady-state temperature profile of a window (or wall). The physical concept being explored here is heat conduction. The relatively simple equation that we will be dealing with for heat flow is:

     P/A = -k dT/dx
    where P/A is the power per area (or energy per time per area) flowing through a surface, k is the conductivity and dT/dx is the temperature gradient in the direction the heat is flowing.

    To solve this equation numerical we will convert the differential equation to a difference equation. The idea behind a difference equation is that derivatives are approximated as small (but non-infinitesimal) Δ's. So here we have

     ΔT = - ((P/A)/k) Δx.  
    In order to apply this difference equation in a program we have to convert the Δ's into differences between variables. In this case I am going to give you the temperature on the outside of the window. To find the temperature a small distance from the outside of the window we would say:
     T1 = T0 + (((P/A)/k)) Δx.
    (Note that by starting at the outside and working are way into the house, we have flipped the sign on the heat flux term - if you prefer you can think of P/A as negative).

    We can generalize this scheme to find the temperature at any place along the window based on the temperature at the previous location:

     Ti+1 = Ti + ((P/A)/ki+1) Δx.
    The last equation is the one that you will want to translate into code for this program. Your program should contain a loop which iterates through to find the temperature based on the temperature at the previous location. Your program should save the temperature at all locations using an array. Note that you will also need an array which keeps track of the location (x) for each temperature. You will to use an equation similar to:
     x1+1 = xi + Δx .
    Your program should output the temperature at the end of each layer of material and create a plot of your results with PLPlot. Note that you may want to use lines [ pls->line(npts, x, y); ] in the plots instead of points. Also, note that in this case there is no need to send all of your data points to the plotting program, since with so many data points you would create very large plot files. Instead, you should make smaller arrays where you only plot every tenth or even hundredth point. (E.g. save points 0, 100, 200, 300, ... into new arrays.) Listed below are the conditions that you should test your program with. You should save these conditions directly in your code. Use a Δx of 1.0x10-5 m and an outside temperature of -20.0 degrees C for all runs.

    P/A k1 width1 k2 width2 k3 width3
    W/m2 W/m/deg. C m W/m/deg. C mW/m/deg. C m
    0.0 0.84 0.0055 0.018 0.003 0.84 0.0055
    400.0 0.84 0.0055 0.018 0.003 0.84 0.0055
    400.0 0.84 0.0055 0.84 0.003 0.84 0.0055
    400.0 0.84 0.0055 0.024 0.003 0.84 0.0055
    400.0 0.84 0.0055 0.018 0.0055 0.84 0.0055

    The cases above correspond to several physical situations. The material with the highest conductivity is glass, the material with the middle conductivity is air, and the material with the lowest conductivity is argon gas. The first situation is a window with no heat source. In the second case there is a heat source and a window that has two panes of glass with a smaller argon gap between the glass layers. In the fourth case the argon gas is replaced with air. In the third case the argon is replaced by glass. In the last case a larger argon gap is used. Note that the assumptions for these cases are fairly simplistic. We have assumed infinitely long walls made of only the listed materials. Also, we have assumed no convection.

    For this program, turn in the output of your program running for each of the cases. Comment on the results of each run of the program. Do the results seem reasonable? Why or why not?

  3. Review Problems from book:

    5.2, 5.6, 6.4
  4. Project Update

    For those of you taking 322, please send me a copy of the code that you have written so far for your project. I don't expect perfect code (it may not even compile at this point), but you should have something.