|
|
Class Text
Warnick, Numerical Methods for Engineering, 2nd Edition, IET Press, 2020
Grading
| Assignments: (75%) | Homework assignments are integrated with the lectures. We start each lecture by discussing the previous homework assignment together as a class. Homework assignments include derivations of key results from the course material, writing numerical codes, and applying those codes to various types of application problems. Most assignments are self-checking. You can know immediately whether or not your results are correct. Come to class with codes already written and with questions and observations about the assignment. Your results, questions, and challenges with the assignments will be used to facilitate our class discussions. For assignments, upload a single PDF file in Learning Suite including your code, numerical results, plots as needed, and brief comments on your observations about the results. |
| Quizzes: (5%) | Quizzes will allow you to assess how much you are learning about the numerical methods we are studying. |
| Code project: (10%) | Choose one of the major numerical methods, implement a 3D version of the method, and apply it to a problem of interest to you or in your research. |
| Midterm, oral exam, and final (10%): | The midterm, oral exam, and final exam will cover important topics and derivations from the course. The final will be given at the scheduled place and time as listed by the university. |
Policies
AI: This class is about your learning and personal growth as part of your "quest for perfection and eternal life." Use AI to rough out codes, debug issues with your codes, and as a learning tool to help you deepen your insights. All algorithms that we will cover in this class have already been implemented and most are available as commercial packages, so this class is not about who can use AI tools to generate working codes with the least effort. To make AI useful to you in the learning process, ask creative questions beyond just a basic prompt. To pass exams, you will need to make sure that you are learning the underlying principles behing the algorithms, how they are implemented, and how they behave for different types of problems in terms of accuracy and computational efficiency.
Group study: I encourage conversing about interesting points, behavior of numerical results, and interpretation of mathematical formulas. Codes must be developed individually. Sharing of codes or code fragments is not allowed.
Figures: Label all plot axes including units. When comparing results, overlay them on the same plot, use a legend to identify multiple curves, and be sure that different curves are distinguishable. Use a loglog or semilog plot for numbers that become very large or very small or have a power law behavior.
Coding
Debugging even short numerical codes can take many hours. In order to reduce the time required to obtain working codes, here are several suggestions:- AI is a great tool for debugging. AI makes mistakes, so it's valuable to make the effort to understand the concepts underlying the method you are implementing.
- One approach to coding is to sit down and start typing before you have a clear idea in your mind about how a method works. This shortcut is useful to get a quick and dirty code but increases debugging time down the road. A better way is to map out on paper how the algorithm works and derive key lines of code from relevant equations. Save these notes for your assignments and turn them in as documentation.
- Check your code against an analytical solution or a problem with a known qualitative behavior.
- The worst debugging technique is to change numbers or commands blindly and rerun the code over and over again. This is useful in rare situations such as fixing a minus sign you don't care to derive by hand, but is most often a waste of time. Instead, break your code into sections and test each separately. It is extremely difficult to simultaneously debug more than one complex code segment.
- Grab a snack and let your code sit for a while, then come back and read over it slowly. Bugs will jump out at you.
- If a code is not working properly, you can often get a hint as to the cause of the problem by looking at the results for a test case. Devise simple experiments for which you know the answer, so you can localize the problem to a specific section of code.
- As a last resort, rewrite a short code from scratch. This can sometimes be quicker than finding an obscure bug.
- Use indenting, spaces around equal signs and other operators, and avoid long lines of code.
- Define physical constants, upper limits for indices, and other values as variables in a parameter section at the beginning of the code. Numerical constants should not be repeated multiple times in a code.
- Avoid the overuse of functions, especially in the early stages of development. Creating functions for commonly used operations saves time, but with matlab, it is sometimes easier to use scripts rather than functions for main programs. This helps when debugging, because internal variables are accessible interactively when a program breaks. One a program is debugged, if you prefer to use it as a function, create a top level script which stores the function calls rather than entering them interactively.
- Comment your code. If you leave a code and return to it after a few days it may be hard to follow without comments. Describe in a few words what each variable represents and the function of each line or group of a few lines. Put in clear dividers between major code sections. Write out equations in text notation. Document tricky minus signs and constants.
- A given algorithm is often modified and used in different ways for multiple problems. Saving multiple versions of a code is good practice and helps when rerunning a specific analysis. This should be done only when a code is sufficiently mature and unlikely to change. One approach to managing variations is to keep a single copy of the code and embed parameters and short sections of code for each type of problem inside if statements that can be turned on and off as needed.
- Include commands used to create and format plots at the end of a code rather than entering them interactively. When plotting results within a loop po watch a computation evolve, updating the plot every cycle can slow down the code. To avoid this, update the plot, say, every tenth cycle using if mod(n,10)==0.
- For two-dimensional data, the first array index should represent the x coordinate of the physical domain and the second index should represent y, with the (1,1) element corresponding to the lower left corner of the physical domain. The matlab commands image and imagesc display arrays using the matrix convention with rows horizontal. To view n-dimensional data in the standard orientation, rotate the array using .' before displaying using image or imagesc.