Engineering Programming and Computation using
MATLAB
Cheng-Liang Chen
PSE
LABORATORY
Department of Chemical Engineering National TAIWAN University
Chen CL
1
Engineering Programming and Computation using
MATLAB
Teach eacher: er: Chen Cheng-Li g-Liang ang Chen
[email protected] Assist Ass istant ant:: Ch Chih ih-Y -Yao ao Lin
[email protected]
Chen CL
2
Textbook and Reference William J. Palm III Introduction to MATLAB 7 for Engineers
Michael B. Cutlip and Mordechai Shacham Problem Solving in Chemical and Biochemical Engineering . . .
Chen CL
3
Table of Contents
MATLAB and Problem Solving
Array and Matrix Operations
Files, Functions, and Data Structures
Programming with MATLAB
Plotting and Model Building
Linear Algebraic Equations
Probability, Statistics, and Interpolation
Numerical Calculus, Differential Equations, and Simulink
Symbolic Processing with MATLAB
Problem Solving in Chemical Engineering: Basic Principles and Calculations; Thermodynamics; Reaction Engineering; Phase Equilibrium and Distillation; (Fluid Mechanics; Heat Transfer;
Chen CL
4
Some Notes
Teaching and designated exercise during class: Wednesday 1 : 20 Thursday 1 : 20 1 : 20
∼ ∼ ∼
3 : 10 2 : 10 3 : 10
(option 1: each week) (option 2: every 2 weeks)
One or two student(s) per group
Prepare one document file for each exercise designated during class:
B95524063 EX01 doc 1 . − −
reg. #
ex #
version
doc file
Document file should include title of this exercise, name(s) and registered number(s), simple problem statement and main results , M-file , figure(s), table(s), . . . E-mail your document file immediately to teaching assistant (Lin,
[email protected] ) before you leave computer room You can modify your report and e-mail it again to teaching assistant after the class (use another file name: B95524063 -EX01 - 2 .doc ) new ver
Examinations: 2 mid-terms and 1 final
(25% + 25% + 25% )
Designated exercises and Performance during class:
(25%)
Chen CL
5
Learning Objectives in Engineering Programming
We are not going to train you as a programmer or software engineer Main learning objectives in this course: To use computational tool(s) for solving engineering problems effectively
Understand and analyze the problem Model formulation Solution method (analytical or numerical ?) Computer program for solving the problem
Which programming language ? FORTRAN ? C++ ? . . .
No Magic, only BASIC
Chen CL
6
Milestones in Computer Science BC 3000
Abacus
China
1642
Blaise Pascal
Pascaline
(Frence, mathematician) a machine for addition
1801
Joseph-Marie Jacquard
Jacquard loom
use punched cards to control a machine
1822
Charles Babbage
Difference engine
simple computations
1889
Herman Hollerith
A “machine”
using punched cards for US population statistics (7.5 → 2.5 years)
1896
Herman Hollerith
Tabulating Machine Company
International
1937
Alan Turing
Turing Machine
(England) A prototype machine for digital computation
1938
William Hewlett, David Packard
HewlettPackard Company
(Stanford, Palo Alto)
Business
Machines
Corporation (1924/2/14)
Chen CL
7
Milestones in Computer Science 1939
John V. Atanasoff, Clifford Berry
AtanasoffBerry Computer
Iowa State Univ. The 1st electronic
1944 Havard Univ. (+ IBM)
Mark 1
A machine for automatic computation (8 × 51 ft2)
1945
John Neumann
von
Stored program
Basic concept for modern computer hardware
1946
John W. Mauchly, J. Presper Eckert Jr
ENIAC
Electronic Numerical Integrator And Computer. The first vacuum tube
1952
Grace Murray Hopper
A-0
The first compiler
1957
John Backus
FORTRAN
FORmula TRANslation language. (IBM) The first high level computer
computer. Electrical signals for information codes
computer (30 tons, 30 × 50 ft2). University of Pennsylvania.
language. Emphasize scientific programming
Chen CL
8
Milestones in Computer Science 1959
Honeywell
Honeywell
The first transistor-based computer
400 John McCarthy
LISP
(Carnegie-Mellon) A language for symbolic computation
1963
USA Standard Bureau
ASCII
American Standard Code Information Interchange
1964
IBM
IBM 360
The first integrated circuit computer
Douglas Engelbard
mouse
1965
for
MIT, Bell, GE Multics
Operating System 1968 1970
Noyce, Moore
Grove,
Dennis Ritchie, Kenneth Thompson
Intel
Company Unix OS
Central Processing Units: 4004, 8008, . . . Pentium . . .
Chen CL
9
Milestones in Computer Science 1971
Niklaus Wirth Ray Tomlinson
email
Intel
Intel 4004
Microprocessor, CPU
1972
Dennis Ritchie
C language
(from B)
1975
?
Altair 8800
The first personal computer
1976
Steve Jobs, Steve Wozniak
Apple 1
1977
Steve Jobs, Steve Wozniak
Apple 2
Bill Gates, Paul Allen
Microsoft
Intel
Intel 8086,
1978
Pascal
Integrated
Apple Company
(16 bits)
8088 1981
IBM
IBM PC
(→ IBM compatible PCs)
Circuit
Chen CL
10
Milestones in Computer Science 1982
Intel 80286
Intel
1984 Sony, Philips CD-ROM IBM PC AT IBM 1985 Microsoft
Window 1.0
1986
Intel
Intel 80386
1989
Intel
Intel 80486
Tim Berners-Lee
World Web
1991
Wide
Linus Torvalds Linux
1993 Apple
Intel Microsoft
Personal Digital Assistant Pentium 66 MHz
(16 bits) Use Intel 80286 (32 bits) (announced in 1990) Linus + Unix (Finland)
60,
Windows NT
Chen CL
11
Milestones in Computer Science 1994
1995
? Young David Filo
Netscape and
Yet Anothher Hierarchical Officious Oracle !
YAHOO!
James Gosling JAVA Windows 95 Microsoft
Java Coffee ?! (Sun) with Internet Explorer 1.0
1997 Intel
Pentium II
1998 Microsoft Larry Page, Sergey Brin
Windows 98
1999 Intel
Pentium Celeron
2000 Microsoft
Windows 2000 (from NT) Pentium 4
98 → Windows Me (Millennium edition)
2001 Microsoft
Windows XP
(eXPerience, from Windows 95, NT)
2003 Intel
Pentium M
(Intel Centrino)
Intel
(Stanford)
Google
III,
Chen CL
12
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language)
(Assembly Language)
1960 1965 1970 r 1975 a e Y
1980 1985 1990 1995 2000
01011010
ADD
Chen CL
13
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language)
FORTRAN
1960 1965 1970
DO 7, LOOP = 1,5 READ *, X, Y
r 1975 a e Y
1980 1985 1990 1995 2000
AVE=(X+Y)/2.0 PRINT *, X,Y,AVE 7 CONTINUE END
(Assembly Language)
Chen CL
14
Progress of Programming Languages Progress of Programming Languages 1955 1960
(Machine Language)
FORTRAN COBOL
1965 1970
01 EMPLOYEE−RECORD 05 EMPLOYEE−NUMBER PIC 9(5)
r 1975 a e Y
1980
05 EMPLOYEE−NAME 05 BIRTH−DATE 10 BIRTH−MONTH 10 FILLER 10 BIRTH−DAY
1985
1995 2000
PIC 99
PIC X PIC 99
05 DATE−HIRED 10 MONTH−HIRED 10 FILLER
1990
PIC X(30)
10 DAY−HIRED
PIC 99
PIC X PIC 99
(Assembly Language)
Chen CL
15
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language) LISP
FORTRAN
(Assembly Language)
COBOL
1960 1965 1970
(defun length (x) PROLOG
r 1975 a e Y
(t(+1 (length (cdr x)))))) SCHEME
1990 1995 2000
(length ’(I Love Computers)’) 3
1980 1985
(cond ((null x) 0)
COMMON LISP
CLOS
Chen CL
16
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language)
LISP
FORTRAN
(Assembly Language)
COBOL
1960
BASIC
1965 1970 PROLOG
r 1975 a e Y
SCHEME
Dim i, sum sum = 0 For i = 1 to 10
1980
sum = sum + 1 Next i
1985 1990
COMMON LISP
CLOS VISUAL
1995 2000
BASIC
Chen CL
17
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language) LISP
FORTRAN
(Assembly Language)
COBOL
1960
ALGOL60
BASIC
1965 1970
PASCAL
PROLOG
r 1975 a e Y
SCHEME
1980 1985
MODULA−2 COMMON LISP
if (i > 0) then x := 10 else
1990
CLOS
MODULA−3
y := 5 VISUAL
1995 2000
BASIC
Chen CL
18
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language) LISP
FORTRAN
(Assembly Language)
COBOL
1960
ALGOL60 CPL
BASIC
1965 1970 r 1975 a e Y
PASCAL
C
PROLOG SCHEME
1980 1985
MODULA−2 COMMON LISP
if (i > 0) x = 10; else
1990
CLOS
MODULA−3
y = 5; VISUAL
1995 2000
BASIC
Chen CL
19
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language)
LISP
FORTRAN
(Assembly Language)
COBOL
1960
ALGOL60 CPL
BASIC
1965 SIMULA
1970 PROLOG
r 1975 a e Y
SCHEME SMALLTALK
1980 1985 1990
PASCAL
C
COMMON LISP
MODULA−2
C++
MODULA−3 CLOS VISUAL
1995
C++
Standard
2000
BASIC
Chen CL
20
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language)
LISP
FORTRAN
(Assembly Language)
COBOL
1960
ALGOL60 CPL
BASIC
1965 SIMULA
1970 r 1975 a e Y
SCHEME SMALLTALK
1980 1985 1990
PASCAL
C
PROLOG
ADA
C++
COMMON LISP
MODULA−3 CLOS VISUAL
1995 2000
MODULA−2
JAVA
C++
Standard
BASIC
Chen CL
21
Progress of Programming Languages Progress of Programming Languages 1955
(Machine Language)
LISP
FORTRAN
(Assembly Language)
COBOL
1960
ALGOL60 CPL
BASIC
1965 SIMULA
1970 r 1975 a e Y
SCHEME SMALLTALK
1980 1985 1990
PASCAL
C
PROLOG
MATLAB ADA
C++
COMMON LISP
MODULA−3 CLOS VISUAL
1995 2000
MODULA−2
JAVA
C++
Standard
BASIC
Chen CL
22
Some High-level Programming Languages Summary Language
Date Application Area
Origin of Names
FORTRAN
IBM (1957)
Scientific programming
FORmula TRANslation language
LISP
MIT (1958)
Symbolic computation (AI)
LISp Processing
COBOL
USA (1959)
Business data processing
COmmon Business-Oriented Language
Simple on PC
Beginner’s All Purpose Symbolic Instruction Code
Systems programming
Predecessor language was named B
Symbolic computation (AI)
PROgramming LOGic (Frence)
USA (1980)
Real-time distributed systems
Ada Augusta Byron collaborated with nineteenthcentury computer pioneer Charles Babbage
(1980)
Graphical user interfaces; Object-oriented programming
Objects “talk” to one another via messages
Supports objects and Objected-oriented programming
Incremental modification of C (++ is the C increment operator)
Supports Web programming
Originally named “Oak”
BASIC C PROLOG Ada Smalltalk
(1965) Bell (1972) (1972)
C++ JAVA
SUN (1995)
→
Common Lisp Object System
Chen CL
23
MATLAB ?
MATrix LABoratory
In 1978, Professor Cleve Moler (New Mexico University, USA) used FORTRAN to write the MATLAB for applications involving matrices , linear algebra , and numerical analysis
In 1984, Jack Little (Stanford University) used C to rewrite and to commercialize the MATLAB software (MathWorks Company)
MATLAB is both a computer programming language and
an interactive software environment for using that language effectively
Chen CL
24
Why MATLAB ? Outstanding Features
Significantly simpler programming
Continuity (no distinction) among integer, real, and complex values (any variable can take any type of number without special declaration)
Extended range of numbers and their accuracy (all in double precision)
Extensive graphic tools including graphic user interface functions
A comprehensive mathematical library
Capability of linking with traditional programming languages
Transportability of MATLAB programs
MATLAB has a number of add-on software modules, called toolboxes, that perform more specialized computations. All toolboxes run under the core MATLAB program
Chen CL
25
Thank You for Your Attention Questions Are Welcome