Worksheet 1, PHY301 - Spring 2012

PROBLEMS

1. Write a C++ code that prints out your name.

2. Write a C++ code that calculates and prints out the following sum (where i is in radians)

\begin{displaymath}(\sum_{i=0}^{100} Sin(i))^2
\end{displaymath} (1)

Check your result by doing the same calculation in Mathematica.

3. Write a C++ code that finds the integral of a function f(x) over the interval (a,b) using the simplest equally spaced Trapezoid rule. As an example use

\begin{displaymath}\int_0^1 e^{-x^2} dx.
\end{displaymath} (2)

Tabulate the numerical result you get for this integral as a function of the number of ``mesh points'' that you used on the interval (0,1).

Examine how your result converges as the number of points is increased.

Also calculate the integral above using Mathematica to check you got the limit right.


How to compile and run a C++ code in 1240 BPS

To compile:

g++ -o file.exe file.c

To execute:

./file.exe