Introduction to Scientific Programming

Instructor: Leon Kaganovskiy
Office: HNS 110 or HNS 204 (Physics Computer Lab), Office Phone: 487-4118
Office Hours:

Mon: 11-12:30 and 4-6,   Tue :  4-6 (office/computer lab HNS 204),  Wed: 11-12:30 and 4-6,  Thu :  research day,  Fri   :  4:30-6:30 (office/computer lab HNS 204)

I am available at other times by appointment.   

email: lkaganovskiy@ncf.edu - best way to ask a question.    Also if you need me ASAP:  (941) 366-6134;  (941) 961-3896

 

Books:

Title:

Introduction to Matlab 7 for Engineers

ISBN:

0072548185

Publisher:

McGraw-Hill Professional

Author(s):

William J Palm

Format:

Hardcover, 682 pages

Publication Date:

Jul 23, 2004

Introduction to Engineering Programming: Solving Problems with Algorithms
James Paul Holloway
Willey Publishing,  ISBN: 0-471-20215-0 Paperback  448 pages  April 2003

 

Course Goals and Objectives: 

This course is an interdisciplinary introduction to Algorithms and Programming for science students.   It is a part of LAC curriculum.  It emphasizes algorithms and programming tools relevant to such students.  We start with Matlab - the programming package for the scientific problems and later move to compiled language C++.   The course introduces students to the most important programming concepts such as algorithms, sequences, selections, loops, functions, procedures, passing by reference vs. by value, numeric and string types, arrays, vectors, pointers, structures, structure arrays, and classes.   The beginning Matlab part of the course, in addition, introduces a number of Matlab-specific commands to solve linear systems, differential equations, find polynomial roots etc…  This course serves as an informal prerequisite for many science classes which require programming.  Work required of students includes weekly homework and substantial programming projects which counts 50% of the grade.  The other 50% comes from two exams..  

Also I would like to continue for the spring half term with more advanced and interesting Matlab features which allow us to solve Linear Equations, study Probability and Statistics, Interpolation, Numerical Calculus and Differential Equations, as well as Symbolic Math in Matlab and Maple.

Minimal Prerequisites: The course is at the introductory - freshmen/sophomore level.  It should be accessible to any students who plan to major in Science.  There are no specific prerequisites for the course - only interest in programming and science problems.  To some extent, the course assumes fluency with high school Mathematics.   Having taken Calculus may make it easier, but it is not necessary.  We do not explicitly use Calculus and all the new constructs are introduced from scratch.   The course does NOT assume any previous programming experience.

Grading Policy: The final grade will be based on tests and problems, as follows:

  1. There will be two exams (may be three) - one for the Matlab part of the course and one for C++, and each will count 25% of the course grade.
  2. Homework assignments will count 50% of the course grade. Late homework will be accepted only by special permission of the instructor.

Topics to be covered and Homework Assigned  (exact due dates will be announced in class).

This course plan may be modified during the semester. Such modifications will be announced in advance during class periods, and the students are responsible for keeping abreast of such changes. The WWW page for the course will also be used to list assignments and other notes, and students are responsible for checking this web page regularly.

Introduction to Matlab

Unfortunately this and all the other texts I could find try to give encyclopedic treatment of Matlab features in each chapter, which makes it a good reference later, but could be overwhelming for a beginner.  In my class Power Point Presentations I will underline all the topics which you really have to know, other details of the text have to be read for your information, but you will not be tested on them.  In addition, in the lectures, I will underline all the topics which we will skip.

Chapter 1 - An Overview of Matlab - introduces the Matlab environment and all of the main constructs (which are studied in greater detail in Ch 4 - Programming in Matlab).

                   HW: 2, 4, 7, 8, 14, 18, 19, 21, 23, 28, 35, 36, 37, 40

Chapter 2 - Numeric Cell and Structure arrays - introduces arrays - the most important data structure in Matlab.  We will skip cell arrays and study only briefly structure arrays.

                    HW: 1, 5, 6, 7, 9, 13, 15, 17, 18, 21, 23, 25, 28, 32, 37, 42, 44, 45, 46, 50, 51, 52, 53

Chapter 3 - Functions and Files - introduces a large class of Matlab standard built-in functions, user defined functions, as well as how to deal with data files.   We will skip section 3.3.

                    HW: 2, 6, 9, 10, 13, 15, 17

Chapter 4 - Programming in Matlab - a more detailed study of basic programming structures such as relational operators, conditional statements, and loops.

                    HW:  6, 7, 9, 11, 12, 14, 17, 25, 28, 32 part c can be plotted using the following commands:

                                    contour([0:0.2:2],[0:0.2:2],T),xlabel(x'),ylabel('y')

                                    surface([0:0.2:2],[0:0.2:2],T),xlabel('x'),ylabel("y'),zlabel('Temp (deg F)')

                                    mesh([0:0.2:2],[0:0.2:2],T),xlabel('x'),ylabel('y'), zlabel('Temp (deg F)'),

                                    33, 40, 41

Chapter 5 - Advanced Plotting and Model Building - 2D plots, subplots and overlays, interactive plotting, regression, 3D plots

                    HW: 3, 6, 15, 18, 31, 49, 51

Projects:  Circle FittingSmall Projects 1-4, Read Pages 114-116 in Holloway book on Time Stepping, Stopping Distance of a Car

                Predator-Pray - do in Matlab Project 18 p145 of Holloway book, Histograms

Chapters 6-10 - material for possible future half course in the spring half term.

 

Introduction to C++

C++ is one of the large class of compiled languages.  It runs much faster than Matlab, but does not have many of the wonderful features of Matlab.   No interaction, no plotting etc..., no access to intermediate results after the run, no easy debugging.

String handling, databases etc... are not done in Matlab, but in C++ or a more specialized languages.

It is a commercially acceptable language (Fortran 90 is a fast compiled Science-oriented language, very close to Matlab and quite nice, but it is not used commercially anymore, so unfortunately I cannot teach it to you).

On the bright side - Holloway book is very Science oriented.  It contains many excellent and useful algorithms.   Thus, you learn C++ and get important knowledge of algorithms.

Chapter 1 - Introduction - calling environment, programming languages.   Somewhat basic, but introduces a different view of programming.   

                    HW: Question 6,  Projects 1 (extra credit for the use of sqrt), 2, 3

Chapter 2 - Sequence -expressions, functions vs procedures, side effects, input and output in C++, files

                    HW: Questions # 8, 13; Projects # 1, 2, 5 (little tricky), 6, 7, 9, 11

Chapter 3 - Iteration -loops, ordering work in a loop, iterative solutions of equations, time stepping, slicing pi, the area under the curve.

                    HW: Projects # 1, 2, 4 (no need for algebraic changes, just keep running sums), 6, 7, 8 (longer end of term), 10, 12(related to 10), 13, 18 (longer, end of term?)

Chapter 4 - Selection - calendar algorithm, bisection algorithm, recursion.

                    HW: Projects # 1, 2, 4, 6, 9 (Simplest Monte Carlo simulation), 10 (Example of Random Walk - end of the term project)

Chapter 5 -  Dealing with Data - numeric types, integer, floating, type conversions, constants and aliases, references, strings, files, generic routines and types.

                    HW: Projects # 3, 5

Chapter 6 - Array Semantics - strings, substrings, vectors, merge-sort, smoothing the data, matrix-vector multiplication, solution of linear systems for tri-diagonal case and

                    general Gaussian Elimination, native pointers, command line

                    HW: Projects # 1 (use isalpha(), s.push_back(), toupper()), 4, 5, 6

Chapter 7 - skip

                    Aggregate Semantics - packages of related data, structures and classes, image files, lines and plotting, gravity problems, constructors and destructors, matrix class

                    HW:  Q 19??

 

We will consider some topics from the book below.   In particular, structures, natural arrays, object oriented programming is done better in this book.   It should be in the library.

Programming and Problem Solving with C++, Fourth Edition
Nell Dale, University of Texas, Austin, Chip Weems, University of Massachusetts, Amherst                                                                                                                                                                          ISBN 13: 9780763707989
ISBN 10: 0763707988

Chapter 10 - we look at the second part of this chapter, starting with typedef and enum types.

                    HW: Must write drivers to test your code segments: 

                            Exam Preparation: #15-17;   Programming Warm Up:  # 8, 10-15 

Chapter 11 - Structured Types, Data Abstraction and Classes

                    HW:  Exam Preparation: #5, 8-10; 14-17   Programming Warm Up:  # 1-5, 14-18

Chapter 12 - Arrays

                    HW:  Exam Preparation: #12-15, 19, 21  Programming Warm Up:  # 7-12,  17-19

Chapter 13 - Array-based Lists

                    HW: Exam Preparation: #3, 4, 7, 11, 12  Programming Warm Up:  # 1, 2, 4-7, 10, 11