Worksheet 1, PHY301 - Fall 2003
Due Sept. 12 - two weeks
One way to begin learning C++ programming would be to study
a bunch of simple working programs. If you choose that route,
a suitable collection can be found at
MSU CSE231
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)
|
(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
|
(2) |
Plot the value of this integral(using xmgrace)
as a function of the
number of ``mesh points'' that you used on the interval
(0,1). Also calculate the integral above using
Mathematica to check that you got it right.
4. Do the same, but use the integration method in which the interval is
again divided into equal intervals, but the integrand is evaluated only
at the centers of those intervals. Use equal weights. Again check the
answer with Mathematica.
5. Repeat problem 4, but this time make the integrand more challenging
by including a singular factor 1/sqrt(x) in it. (You could instead
include a factor 1/sqrt(x-0.5) in it; that will challenge your ability
to use Mathematica.)
Info on xmgrace:
http://plasma-gate.weizmann.ac.il/Grace/
How to compile and run a C++ code in 1240 BPS
To compile:
g++ -o file.exe file.c
To execute:
./file.exe