Always hand in:
- written solutions to any questions
- a paper print-out of well-commented code. Include a multiline comment at
the top of your code with (i) the assignment name, (ii) your name,
and (iii) the date you handed in all elements of the assignment
- paper print-out of output (graph or text)
- also, e-mail me (y-lithwick@northwestern.edu) the code with your name and
the exercise number in the subject line
Assignment #4
[5 pts, due 2pm, April 10]
-
Here is the skeleton of a general purpose integrator
of ordinary differential equations: integ.c.
Fill in the code only where I marked XXX.
The final code should run and reproduce question 2
from assignment 3. Note that 'step' calls
'derivs', and I've coded in the 'derivs' for you.
You will hopefully be able to use this code in future
assignments for solving many different ODE's with different
methods.
-
Use your general purpose integrator from question 1
to integrate equations
1.12 in the book (see problem 1.5 [pdf]), with initially
NA=100, NB=0, tau=1.
Note: you should only have to modify the functions
'initialize' and 'derivs'.
-
For this question, you have two options.
Either
finish working through the square-bracketed sections of
the Online C tutorial below, or
do problem 1.6 in the book with your general purpose
integrator.
If you are doing the
Online C tutorial, write on your solution the sections of the Online C
Tutorial you've done.
Following is a list of chapters in the Online C Tutorial.
I recommend you do the pages enclosed in square brackets,
because these are the most
important pages for this course. The remaining sections
are not necessary, but are still worth doing for learning
C.
- Introduction
[c_000-c_005]
- Declaring Variables
[c_006-c_009]
- Preprocessor Statements
[c_010-c_012]
- Arithmetic Operators
[c_013-c_015]
- Programming Style
[c_015a]
- Keyboard Input
[c_016-c_017]
- Relational Operators
[c_018]
- For and while loops
[c_019-c_022]
- If, if else, relational operators
[c_024-c_027b, c_029]
- Switch/case
- String and character handling
- Data validation examples
- Conditional expression operator
- Arrays
[c_034-c_041]
- Functions
[c_042-c_050]
- Additional assignment operator
[c_051-c_052, c_054]
- Sample programs so far
- Handling user input and Validation
- Formatters for printf() and scanf(),
bit operations
- Structures
- Data conversion with itoa() and
atoi()
- Files
[c_069]
- Pointers
[c_076-c_077, c_0771]
- Linked Lists
- Dynamic Memory Allocation
- Preprocessor Statements, Macros,
Conditional Compilation, typedef
- Eumerated Data Types
- Unions
- Register based variables, null
statements and strings
- Command Line Arguments
- Pointers to functions
- Formatters for characters and strings
- System Calls
-
To learn more about pointers, you can go through this
pointer tutorial.
It gets to more advanced topics than are needed in this course. But it
is useful if you want to learn more about pointers.
(Chapter 5 requires learning about structures. You could either
skip it, or learn about structures first.)