Skip to Main Content Skip to Search
Accelerating the pace of engineering and science

 

Newsletters - MATLAB News & Notes

Introductory Programming Using MATLAB

by K-Y. Daisy Fan and David I. Schwartz, Cornell University

At Cornell, the Department of Computer Science teaches a variety of introductory programming courses that offer MATLAB and Java. This article describes the courses and our experiences in teaching them.

MATLAB is used throughout the engineering curriculum and in other programs at Cornell. In upper-level courses, it allows instructors to focus on conceptual rather than basic computing issues. Besides the expectation of student familiarity, professors use MATLAB in the introductory programming course because:

  • Many beginning programmers find MATLAB easy to use
  • We can show powerful computation techniques early
  • The command window provides immediate feedback
  • The numerous, easily accessible demos motivate students

In the Department of Computer Science, we developed introductory programming courses to help students develop programming problem-solving skills. They are intended to help students gain confidence and expand their computing knowledge. The College of Engineering has a first-year program in which all students, regardless of their majors, enroll in one introductory programming course. This course also serves the first-year students intending to major in Computer Science from the College of Arts and Science.

To provide our students with versatile programming tools, we teach two languages: Java and MATLAB. We accommodate both the common curriculum philosophy and the varying students' interests by offering two introductory programming tracks:

  • CS100M comprises seven weeks each of MATLAB and Java. This track focuses on mathematics, engineering application, and computational science.
  • CS100J comprises 12 weeks of Java and two weeks of MATLAB. This track presents problems with less of a mathematical focus.

In both tracks, students learn how to develop algorithms, organize their code, write control structures and functions, use arrays, and plot data. In CS100M, basic programming concepts are taught with MATLAB, followed by object-oriented programming with Java. CS100J starts with Java and ends with a brisk introduction to MATLAB with a focus on syntax and simple applications. We coordinate the two tracks to ensure that students gain equal expertise in programming.

To provide an extra "edge" and improve confidence for students who have little to no programming experience, we also offer CS99, a pre-CS100 course to help bridge the gap. CS99 slows the pace and provides a subset of the MATLAB component of CS100M.

We use interesting examples to demonstrate programming techniques and to motivate students. The estimation of using a Monte Carlo simulation example involves mathematical and statistical theories. In order to estimate , we simulate a game of darts on a square board. Let N be the number of darts thrown randomly over a square domain of area L x L. A circle inscribed in the square then has diameter L and an area of . Let the number of darts N be the area of the square domain:

(1) .

Then the number of darts that fall inside the circle, Nc, is the area of the circle:

(2)

Substitute equation (1) into (2) to get :
(3)

Students use an increasing number of darts to improve the approxi-mation and repeat the dart game many times to obtain an average value of . Figure 1 shows four simulations with 10, 100, 1000, and 10000 darts. By using the familiar mathematical constant , students learn several programming concepts:

Figure 1. Monte Carlo estimation of . Graphics were created using MATLAB. Click on image see enlarged view

  • Vector data structure
  • Generation of random numbers
  • Simulation of systems
  • Graphics

Other problems that students solve using MATLAB include:

  • Computational genomics
  • Cryptography
  • Numerical solution of non-linear equations
  • Condorcet's voting scheme
  • Tic Tac Toe (playing against the computer)

Next Article

Contact sales
Subscribe to newsletters