PHYS 105:  Introduction to Computational Physics

Spring 2008

Homework #1
(Due:  April 15, 2008)




  1. Do exercises 2(b) and 3 from In-class exercises #1. Turn in both programs and the requested graph in exercise 3.

  2. Write a program to sum the series

    \begin{displaymath}
f_N(x) \ =\ \sum_{n=1}^N \, \frac2{\pi}
\left[ 1-(-1)^n\right]
\frac{\sin(nx)}{n}\,.
\end{displaymath}

    This is the Fourier series representation of the step function

    \begin{displaymath}
f(x) \ =\ \left\{ \begin{array}{rl}
-1,~~ & -\pi < x < 0 \\
1,~~ & ~~0 < x < \pi\,.
\end{array} \right.
\end{displaymath}

    Plot $f(x)$, $f_1(x)$, $f_5(x)$, $f_{10}(x)$, and $f_{100}(x)$ on a single graph, for $0 \le x < \pi$ in steps of $\delta x = \pi/500$. Turn in the graph and a copy of your program.

  3. Consider the motion of a particle in one dimension under uniform acceleration $a$. Let's assume that, at time $t=0$, the particle has position $x_0$ and velocity $v_0$. Then, from elementary physics, we know that the position and velocity of the particle at any time $t$ are given by (in C notation):


    \begin{obeylines}\tt
x = x0 + v0*t + 0.5*a*t*t;
v = v0 + a*t;
\end{obeylines}

    (a) Write a program to evaluate the particle's position $x$ at times $t_i = i\,\delta t$, where $\delta t$ is some time step. Use double variables to represent all quantities, and use the values


    \begin{obeylines}\tt
x0 = 0
v0 = 1
a = -1.5
dt = 0.01
\end{obeylines}

    Use a while loop to continue your calculation until $x<0$, and thereby estimate the time $T_0$ taken for the particle to return to $x
= 0$. Print out this estimate, and compare your result with the analytic result obtained by solving the appropriate quadratic equation.

    (b) Modify your program to print out the values of $t$ and $x$ (one pair per line) after every step (don't print out this output!). Use gpl to plot the trajectory, and verify that the particle does indeed return to $x = 0$ at the time obtained in part (a).

    For part (a), turn in a printout of your program and the output produced when it runs. For part (b), print out and turn in the (clearly labeled) graph.









Steve McMillan 2008-04-07