|
PC-based compiling Course Design Compiling Hints Scanf() information. Assorted C routines. Program files Useful, free, scientific software. Java Code (unmaintained). |
Course InformationCourse Outline and Schedules (Postscript) Lecture Material: Lecture and Topic This outline is a bit confused for a number of reasons. First, each time I teach the course I do different things. Second, the makeup of the class is different each time. Third, the course meets either once or twice each week. Instead, I think I will produce the outline as a series of goals and associate them with which week into the semester those goals should be attempted. One comment I have regarding teaching a course out of my book is the issue of parallel tracks for three topics that I try to merge. First, there is the topic of learning to program inC. Second, there is a topic of learning the math associated with the problems and examples I show. Third, there is the topic of learning some ecological principles that all of this theory is supposed to be about. A single course can't do all three, and my courses usually address only the first topic. However, I try to get students to do projects that incorporate the latter two topics. Goal 1: (week one) The main goal right away is setting up your computer with Cygwin in order to do compilations. Of course, you don't need to use Cygwin; there are many options including using a Linux machine or the University computing environment or, gasp, even buying a compiler for your Windows box. If you have a recent Macintosh which has OS X on it, there is something called Xcode that can be installed that has the C compiler. Perhaps it's already installed on your Macintosh; open up a terminal window and type gcc to see if you have the compiler. If you don't, then it will tell you so. Installing Cygwin can take a great deal of effort, but with recent versions of Cygwin (January 20, 2004) the installation is rather straightforward. Do a Google search or go to my scientific software link for more information. Cygwin is a wonderful way to balance having both a Windows system and a Linux system. Assignment: Download bd.c (from Chapter 2) and compile it. This assignment is extremely easy IF it works for you. It can be extremely frustrating if it doesn't work for you. This assignment will force you to work out the mechanics of compiling programs on your platform. If everything is working correctly, whether you are using Cygwin, Linux, or the compiler on Macintosh OS 10, you should get the series of numbers listed on page 37. You might find that the computer does not recognize your compiled command "xbd". If so, it may mean that your present directory is not listed in your path. These words may not mean anything to you, but you might be able to fix the situation by typing instead "./xbd", which tells the computer to look in the local directory to find the compiled command which you are attempting to execute. If you get numbers but they're not the same as the one's listed on page 37 it most likely means that your random number generator is different from the one I used in the book. If you are using a compiler other than the one available from the free software foundation (go look at my scientific software link [assuming I have updated that web page]), then you may be forced to use a different random number generator. One way to simplify your life and converting my code into something you can use on your machine is outlined by pressing my PC-based compiling link. Goal 2 (week one): The first thing to do if you are new to programming is to understand the three important statements that I cover in Chapter one, section five. We will discuss these statements while we examine the details of Ch.2's bd.c. Assignment: Chapter 2 problems: 1, 8, 10, 11, 13. This set of exercises is designed just to get you programming; the more you program the more you will learn. A quick note: the algorithm outlined in exercise 2.4 is extremely useful when performing averages. Goal 3 (week one): Overview of Ch.3's logbd.c and a discussion of global variables, arrays, and functions. All of these topics are covered in the book. One thing I accidentally left out of the book is a discussion of the scanf() function; I think it's covered by a link you'll find on the left of the Web page. Assignment: Chapter 3 problems: 3, 4, 5, 7, 9, 11. Goal 4 (week 2-3): At this stage in the class -- just two weeks into the semester -- it's a good idea to start working on a smallish programming project. Rather than attempt some science project that actually focuses on an interesting question, it might be better to start with something that has no question but demands developing your programming skills. That's what a few of the problems I've assigned out of the book are supposed to do, but other things come to mind while teaching the course. These are typically more demanding problems. Here is the assignment for spring 2004: Mancala is a game that has been around for several millennia. Do a Google search and you'll find a great deal of information, below are a couple of sites that I found. One of them has a bunch of rules for playing the game, and there are several sites that have interactive games that you can play. Here is the class assignment: Using the rules I describe below, write a computer program that does the following. Set up the main routine to pass play between two players. The players are represented by a function that makes one turn. The function will be passed an array that holds the state of the board (how many stones are in each pit) in one array, the number of stones in the two bowls, and the player number that the function is acting as (either one or two). The arrays holding the numbers of stones will be passed by address and the function will change these arrays to represent the final board state. Again, design the program so that this function takes turns with itself to play both sides of the Board. Also write the program so that the number of cells per side can be changed to an arbitrary value and that the number of stones in each cell can be initialized to an arbitrary number. This problem will be a hard one! start with easy goals. First write the program to simply take one step and pass back the results. Check the results against one of the online programs, or preferably, using your own stones on your desk. Once you've got it working, then you can worry about optimizing the step the function takes. When everybody has their routines finished, we will put them together in one program and have a tournament. (In the end, we may decide that this is just too much work and instead get going on some ecological projects.) Rules: 1) The beginning player chooses one of their pits to pull the stones out of, and drops one stone in each pit and their own bowl in a counterclockwise direction. No stone is placed in the opponent's bowl. 1B) If the player has no stones in their pits, then they forfeit their turn. 2) If the last stone is placed in a pit that has stones in it, then all of the stones, including the one just dropped, are picked up and played as in rule number 1. 3) If the last stone is placed in a pit that has no stones, then the player's turn is over. 4) If the last stone is placed in the players bowl, then the player picks up the stones in any one of their pits and plays them as in rule number 1. 5) When all stones are in one bowl or the other, the game is over, and the player with the most stones in their bowl wins. Mancala game site. Various mancala rules. One year I assigned the following kids game: We will write a program for a game that my kids have --- Hi-Ho Cherry-Oh! It involves 2-4 players. The game is a takeoff on spinning the dreidel. Each player starts with 10 cherries on their tree (the maximum number of cherries a tree can hold). In turn (a hard part of the game) a player spins the spinner (another hard part of the game). With equal probability the spinner can point to one of the following seven items: 1, 2, 3, or 4 cherries; dog; bird; or basket. If it points to cherries, then that number of cherries comes off the player's tree and into his or her basket. If it points to the dog or the bird, two cherries are taken out of the basket and put back onto the tree. (We don't deal with negative numbers, so if there's only one cherry just take out one.) If it points to the basket, then all of the cherries are taken out of the basket and put back onto the tree. (No need to simulate the ensuing emotional distress!) Write the program so that it will run for up to 1000 players. As a function of the number of players, how long does the game last? What is the average number of turns needed to take all the cherries of one's tree? Curtis Smith's result for the Hi-Ho Cherry-Oh! game. (Postscript) ------------------------------------------------------------- 2004 Class take note of the stuff above this line! Meeting 4: T 2/6 Pointers. Assignment: 1) Download the Chapter 5 competition program. Compile and run it. Modify according to problems 5.6 and 5.7. Due date next week. 2) Personalized programming project assignments that correspond in a simple manner with the students' major project. Due March 6. Meeting 5: T 2/13 Files and Postscript images. Assignment: Continuation of personal assignments. Download competition simulation, compile, run, and print out the postscript images. Meeting 6: Th 3/1 Assignment Presentations. Meeting 7: T 3/6 Finish Assignment Presentations. Derive a mathematical representation of one or more of the assignments. Meeting 8: T 3/8 Derive mathematical representations of additional assignments. Assignment: Download, compile, and run the foraging program from Chapter 7 (it uses structures). Meeting 9: T 3/20 Discussion of Structures. Meeting 10: T 3/27 Discussion of Fourth-order Runge-Kutta numerical integration. Assignment: 1) Download, compile, and run the RK4 code from the gynodioecy chapter (pp. 188-189). Either: 2a) modify the code to numerically integrate ODEs near and dear to your heart; Or: 2b) look at Project 6.8 on page 151. Modify the discrete-time food-chain model to be a continuous-time food-chain model and write the resulting ordinary differential equations. Modify the RK4 code to find how long of a stable food-chain you can build. |