PHYS 105: Notes on Homework 1

The actual programming involved in this homework should not pose too many problems -- that is, you should be able to construct simple working programs to sum the series and evaluate the functions in the three problems without too much difficulty. However, a few aspects may be unfamiliar -- specifically, compiling the program (if you use C++) and doing the graphics.
  1. For compilation of a C++ program, please read the following page on the course web site:

         C++ Compilation

    The C++ compiler on our system is called g++. In most cases all you will need to do is

    In Python, simply create a file called program.py containing your Python code, then type
        python program.py
    to run it.

  2. The simplest way to make a graph is to create columns of numbers, then use the gpl program to plot it. More information can be found here on the course web site.

    Simply put, if you want to graph two functions, f(x) and g(x), say, then write the functions in your program and include (in C++) a loop of the form

        for (x = xmin; x <= xmax; x += dx)
            cout << x << " " << f(x) << " " << g(x) << endl;
    
    An equivalent Python code fragment might be
        x = xmin
        while x <= xmax:
            print x, f(x), g(x)
    	x += dx
    
    To plot the graphs on the screen, type
        ./program | gpl -c 1 2 3
    
    or
        python program.py | gpl -c 1 2 3
    
    To save the graphs in a file, type
        ./program | gpl -c 1 2 3 -P > graph.ps
    
    (and similarly for the Python code).

    Don't worry about the details of getting multiple plots on a single graph -- we'll cover that later.

    The gpl program was developed to simplify the plotting process, especially in C++, but note that Python has several very capable packages that can handle graphics internally. For more information on two of them, try googling "python gnuplot" or "python matplotlib." Feel free to use these packages (or another) if you like.

  3. Submitting homeworks by e-mail.

    The current course syllabus calls for homeworks to be submitted as hard-copy. However, as an experiment, you can if you wish submit Homework 1 by e-mail. To do so, please do the following.