You are on page 1of 29

CS 103

Introductory Programming for


Engineers and Scientists
Summer 2015

Disclaimer

Slides will be available on Blackboard after class

Course Staff: Instructor

Dr. Robert Tairas


robert.tairas@vanderbilt.edu
377 Jacobs Hall
Office Hours
Mondays Thursdays, 3:10 pm 4:00 pm
By appointment

Course Staff: Teaching Assistant


Yi Dong
yi.dong@vanderbilt.edu
Office hours in FGH 258:

Mondays - Thursdays: 3:15 pm - 4:30 pm

Textbook

By our very own Dr. J.


Michael Fitzpatrick and
Dr. Akos Ledeczi
Available to purchase as
an iBook (Mac) or PDF
file

Objectives and Methodology

To introduce non-computer science students to


the analysis, design, implementation, testing,
and debugging of programs
Emphasis on using programming techniques to
solve problems

The programming language used is MATLAB

Course Management

All course information will be on Blackboard


http://blackboard.vanderbilt.edu
Sign up for Piazza

You should have received an e-mail invitation


Ask questions
Answer questions
Follow specified rules (no sharing of code)

Course Elements

Good old boring lecture


Class notes (highlights), slides, and code examples
will be available on Blackboard after every class
Do not print out lecture notes on lab printers

In-class exercises
The only way to learn this is by practicing it
Use opportunity to try out what you have just
heard
Quickly realize if you do not understand something
Ask questions

Course Elements

Homework assignments (4 total)


Individual work only
Assigned every Tuesday
Start working ASAP as the material is presented
Will help you get prepared for the exams

Two free late days


Use it to extend a deadline by 24 hours
Use carefully, they are meant for unforeseen
emergencies

Course Elements
Exams (5 total)

Every Friday (except Exam 5 on Thursday)


Exam 5 is your last exam
No final exam in this course

Grading

Component
Exam 1
Exam 2
Exam 3
Exam 4
Exam 5
Assignments

Weight
Two lowest scores:
10% (each) of final grade
Three remaining scores:
15% (each) of final grade
35% of final grade

Honor Code

The Vanderbilt Honor Code governs all work in


this course
If you have questions ask your instructor or visit
the Honor Council website
http://studentorgs.vanderbilt.edu/HonorCouncil/

Honor Code

You are not allowed to ask anyone, e.g.:


How did you do number 4?
What kind of loop did you use on number 4?
Will you look at my code for number 4 and help me
figure out what is wrong with it?

You could, however, ask something like:


I'm having trouble understanding how loops work-will you help me with that loop example we went
over in class?

When in doubt ask the instructor

MATLAB

Installation instructions on Blackboard


Under "MATLAB Access"

Install ASAP

Announcements

Complete Assignment 0-A and 0-B


Both available on Blackboard under "Assignments
Does not require MATLAB

Assignment 1 is posted
Due Tuesday (06/09) at 1:10 pm (start of class)

Copyright 2010

Computer Science

(Photo: Paul Shaffer / UPenn)

(Photo: Oak Ridge National Laboratory)

The study of algorithms for processing


information with computers

1946: ENIAC the first electronic


general-purpose computer

2012: Titan Super computer at Oak Ridge


National Laboratory

(Photo: Oak Ridge National Laboratory)

Algorithm

(Photo: Paul Shaffer / UPenn)

(Photo: Oak Ridge National Laboratory)

A precise step-by-step procedure for performing a


task

1946: ENIAC the first electronic


general-purpose computer

2012: Titan Super computer at Oak Ridge


National Laboratory

(Photo: Oak Ridge National Laboratory)

Computers and Software

Computers can't think for themselves


They need to be told what to do very precisely

When you see a "smart" application


It is all in the software

Flashlight app

(Photo: http://mobiappsexperts.com/how-the-world-has-gone-mobile/)

Why is programming difficult?

Algorithmic thinking is not natural to humans


We are great at things that computers still
cannot do (at least not well)
Intuition
Intelligent, creative and contextual thinking
Natural
language
understanding,
understanding

image

Computers are great at processing large


amounts of data fast
If you tell them what to do and how to do it via a
program

DARPA Robotics Challenge


A competition to develop
semi-autonomous ground
robots that can do complex
tasks in dangerous,
degraded, humanengineered environments

Still, why is it difficult?

But translating a problem to a program that


computers can "understand" requires you to
"think" like a computer
It comes naturally to some
Some others can become quite good with practice
Still some suffer to make this mental switch

The only way to get there (and become good at


it) is by doing it: practice practice practice

Programming

It is a creative process
There are a few flexible building blocks (i.e.,
programming constructs), but you decide which
ones to use, in what order, how to "configure"
them, etc.
There is an infinite number of possibilities
The same problem can be typically solved many
different ways
This makes it challenging, but really rewarding
A well-written program is just like a piece of art

Why is it important?

One of the most important classes you will take


"Everybody" writes programs these days
In engineering, science, business, and other fields
To solve all kinds of problems

"Everything" is run on software these days


e.g., cars, phones, medical devices, factories, traffic
http://spectrum.ieee.org/feb09/7649

Your programming ability may be your most


valuable asset in the job market

Simplified Computer Architecture

Von Neumann Architecture (stored program model)


Your desktop, your laptop, your phone and tablet look just like this

- Stores data and the program


- Volatile (power off erased)

- Keyboard
- Mouse
- Microphone

Input
Devices

Memory

CPU

Storage

Output
Devices

- Monitor
- Printer
- Speaker

- Harddisk, SSD
- Program is loaded into memory for execution
- Non-volatile

"Low-level" Programs

Executable code consists of simple instructions


that the CPU understands and executes directly
(where hardware meets the software)
The programming language that is the textual
representation of the executable code is called
assembly language
Higher level programming languages
Have more powerful instructions
Hence, they are easier to use
Programs get translated into
executable code by another program
(compiler or interpreter)
Image taken from: http://bottomupcs.sourceforge.net/csbu/c1453.htm

Why MATLAB?

Ideal for engineering and science applications


Ideal for solutions to numerical applications

Java and C++ are weak for engineering, science,


and numerical applications

Online testimonies
Go to www.mathworks.com and click on "Solutions"

Variable Names

Rules for naming variables:


Must be 63 characters in length
May contain (only) letters, numbers, and the
underscore
Must begin with a letter
Case sensitive
e.g., cat and cAt are different variables

Syntax and Semantics


x = 5

Syntax refers to the form or structure of a


command

"An assignment statement may be terminated with a


semicolon, a comma, a comment, or the end of line"

Semantics refers to the meaning of a command

"An assignment statement will cause the value assigned


to be printed in the Command Window, unless it is
terminated with a semicolon"