WEEK06
June 14 and June 16
This page contains lectures, examples and assignments for week 6
of the class "Introduction to Scientific Programming".
Lectures:
Examples:
-
area_estimate.cpp,
the outline of a program to estimate the area inside a 2D curve.
We must replace the pseudocode by correct C++ statements,
so that we can draw a rectangle -3<=x<=3, -2<=y<=2 around
the curve 4x*x+9y*y<=36, and use sampling to estimate the area.
-
craps.cpp,
a program which simulates the game of craps.
-
dragon.cpp,
a program which estimates the center of mass of a dragon based on
the image dragon.pgm.
-
dragon.pgm,
a PGM (portable gray map) image of a dragon. The background is white,
which is color 255, and everything else is dragon.
-
dragon.png,
a PNG version of the dragon image.
-
dragon_centroid.png,
a PNG image of the dragon, showing roughly where the program computed the
centroid.
-
duel_many.cpp,
a program which simulates many duels between two players who are each only
50% accurate.
-
duel_once.cpp,
a program which simulates a duel between two players who are each only
50% accurate.
-
fair_dice_simulation.cpp,
a program which simulates many rolls of a pair of dice.
-
integral.cpp,
a program which estimates the integral of x*x+2*x-3 from -4 to 5,
using random sampling with N points. The user enters the value of N.
-
poker_hands2.cpp,
a program which tries to compute the number of possible poker hands
by using functions called choose2(). This program is a rewritten
version of poker_hands which avoids the integer overflow problem.
-
random_demo.cpp
a program which demonstrates the effect of using srand()
to initialize or re-initialize the random number generator.
-
random_double.cpp
a function which demonstrates how to compute a random real number
between 0 and 1.
-
random_double_ab.cpp
a function which demonstrates how to compute a random real number
between A and B.
-
random_int.cpp
a function which demonstrates how to compute a random integer between A and B.
-
random_int_count.txt
the output from random_int_test, which can be plotted by GNUPLOT.
-
random_int_test.cpp
a program which tests RANDOM_INT.
-
random_walk_1d.cpp
a program which simulates a random walk in 1D.
-
random_walk_2d.cpp
a program which simulates a random walk in 2D, in which a spider
and a fly start out in a 40x40 box.
-
random_walk_2d.txt
the step, fly position, spider position, and distance between spider and fly,
for the 2D random walk.
Assignments:
-
In class exercise #6, on Tuesday: Estimate the area in a 2D region.
-
Program Homework #4 is due on Thursday. Please mail your program and output
to Detelina.
-
Program Homework #5, to be assigned on Thursday.
You can go up one level to
the ISC course page.
Last revised on 28 July 2011.