Você está na página 1de 42

Introduction to CZ1102

1
Objective of the module
• prepare the student to approach problem solving in an 
algorithmic way, with an emphasis on computational 
aspect. 
• In particular, elements and practicalities of computer 
programming through the high‐level mathematical 
computing environment will be incorporated in the 
course structure. 
• This is an intensive hands‐on course on computational 
problem solving with many practicals. Major topics: 
Fundamentals of programming language. Arrays and 
structures. Functions and files. Computing using MATLAB. 

2
Detailed syllabus
• Fundamentals of programming language
– computer components and software Hierarchy
– introduction to Matlab
– program design and development
– data types and memory allocation
– relational operators and logical variables
– conditional statement
– loops
– switch structure

3
(cont’)
• Arrays and structures
– vector, matrix and multidimensional arrays
– element access operations
– record and structure arrays
– manipulating of data of different types
– set operations

4
(cont’)
• Functions and files
– elementary mathematical functions
– user defined functions
– arguments and return values
– string handling
– reading and writing data files
– basic paradigms on program debugging 

5
(cont’)
• Computing using MATLAB
– elementary linear algebra operations
– working with M‐files: functions and scripts
– polynomial multiplication and root finding by bisection
– 2D and 3D function plotting 
– data fitting and interpolation
– multi‐dimensional data visualization
– Code vecterization for computing efficiency
– look forward to other programming languages: C and C++

6
References
• Online help resources
– http://www.mathworks.com/help
• Ebooks
– http://www.mathworks.com/moler/index.html
• Book
– Brian H. and D. Valentine, Essential MATLAB for 
scientists and engineers, Academic Press, ISBN‐13: 
978‐0123748836.

7
Timetable
• Lecture 
– Monday
• Tutorial  (odd week)
1. Wed.
2. Fri.
1. Lab (even week)
1. Wed.
2. Fri.

8
Assessment
• Tutorial & Lab 
– 20%
• Two projects
– 20%
– Group project (two members each)
• Final exam (2 A4 size helpsheets)
– 60%

9
Computer and programming

Lecture 1

10
A computer system

Monitor Speaker
(output) (output) System unit
(processor, memory…)

Printer
(output)

Storage devices
(CD-RW, Floppy,
Hard disk, zip,…)
Mouse
(input)
Scanner Keyboard
(input) (input)

11
What Does A Computer Do?
• Computers can perform four general operations,
which comprise the information processing cycle.
– Input
– Process
– Output
– Storage

12
Data and Information

• All computer processing requires data, which is a


collection of raw facts, figures and symbols, such as
numbers, words, images, video and sound, given to the
computer during the input phase.
• Computers manipulate data to create information.
Information is data that is organized, meaningful, and
useful.
• During the output Phase, the information that has been
created is put into some form, such as a printed report.
• The information can also be put in computer storage for
future use.

13
Why Computer is important

• The ability to perform the information processing 
cycle with amazing speed.
• Reliability (low failure rate).
• Accuracy.
• Ability to store huge amounts of data and 
information.
• Ability to communicate with other computers.

14
How Does a Computer Know what to do?

• It must be given a detailed list of instructions, 
called a compute program or software, that tells 
it exactly what to do.
• Before processing a specific job, the computer 
program corresponding to that job must be stored 
in memory.
• Once the program is stored in memory the 
compute can start the operation by executing the 
program instructions one after the other.

15
What Are The Primary Components Of A 
Computer ?
• Input devices.
• Central Processing Unit
– control unit
– arithmetic/logic unit.
• Memory.
• Output devices.
• Storage devices.

16
Input Devices

• Keyboard.

• Mouse.

17
The Central processing Unit
• The central processing unit (CPU) contains electronic 
circuits that cause processing to occur. The CPU 
interprets instructions to the computer, performs the 
logical and arithmetic processing operations, and 
causes the input and output operations to occur. It is 
considered the “brain” of the computer.

18
Memory
• Memory also called Random Access Memory or RAM
(temporary memory) is the main memory of the
computer. It consists of electronic components that
store data including numbers, letters of the alphabet,
graphics and sound. Any information stored in RAM
is lost when the computer is turned off.

• Read Only Memory or ROM is memory that is etched


on a chip that has start‐up directions for your
computer. It is permanent memory.

19
Amount Of RAM In Computers
• The amount of memory in computers is typically
measured in kilobytes or megabytes. One kilobyte (K
or KB) equals approximately 1,000 memory locations
and one megabyte (M or MB) equals approximately
one million locations A memory location, or byte,
usually stores one character.
• Therefore, a computer with 8 MB of memory can
store approximately 8 million characters. One
megabyte can hold approximately 500 pages of text
information.

20
• Output devices make the information resulting from the
processing available for use.
– printer
– computer screen.
• The printer produces a hard
copy of your output

• computer screen produces


a soft copy of your output.

21
Storage Devices
• Auxiliary storage devices are used to store data when 
they are not being used in memory. The most 
common types of auxiliary storage used on personal 
computers are
– floppy disks (hard to see now)
– hard disks 
– CD‐ROM drives.

22
Hard Disks
• Consists of one or more rigid metal plates coated
with a metal oxide material that allows data to be
magnetically recorded on the surface of the platters.
• The hard disk platters spin at a high rate of speed,
typically 5400 to 7200 revolutions per minute (RPM).
• Storage capacities of hard disks up to 2000 GB (one
billion bytes are called a gigabyte).

23
Compact Discs
• A compact disk (CD/DVD), also called an optical disc,
is a flat round, portable storage medium that is
usually 4.75 inch in diameter.
• The capacity of a CD is 650 MB of data.
• The capacity of a DVD is 4GB.

24
How computer is able to interact with users

• Computer software 
– System software
– Application software.

Application Programs
Word-Processors, Spreadsheets, etc
System Software
Compilers, Interpreters, linker etc.
Operating System, Device Drivers
Machine with all its hardware
25
(con’t)
• System software
• Programs written for computer systems
• Example:
• Operating Systems, 
• Compiler, Loader, Linker, Interpreter.
• Application programs
– Programs written for computer users
– Example
• Office
• Web browser 

26
System Software: Operating System
• Operating System is a software, which makes a 
computer to actually work.
• OS acts as an interface between the application 
programs and the machine hardware.
– Loading & running application programs
– Allocating memory & processor time
– Providing input & output facilities
– Managing files of information
• Examples: Windows, Linux, Unix and Mac OS, etc.

27
How to run a program on OS
• Steps that the computer goes through to run a
program:
Memory

Machine language
program
(executable file)
Input Data
Data entered CPU
during execution

Computed results
Program Output
28
Program Execution in CPU
• Steps taken by the CPU to run a program 
(instructions are in machine language):
1. Fetch an instruction
2. Decode (interpret) the instruction
3. Retrieve data, if needed
4. Execute (perform) actual processing
5. Store the results, if needed

29
How to develop an application
• Application (executable code) is developed based on 
source programs (source code)
• Two approaches
– Compilation
– Interpretation

30
Compilation
• Application (executable code) is developed based on 
source programs (source code)
• Source programs are written in programming 
languages
– PL = programming language
• A  PL is
– A special purpose and limited language 
– A set of rules and symbols used to construct a computer 
program
– A language used to interact with the computer

31
Computer Languages
– Machine Language
• Uses binary code
• Machine‐dependent
• Not portable
• Assembly Language
– Uses mnemonics
– Machine‐dependent
– Not usually portable
• High‐Level Language (HLL)
– Uses English‐like language
– Machine independent
– Portable (but must be compiled for different platforms)
– Examples: Pascal, C, C++, Java, Fortran, matlab, etc

32
Machine Language

• The representation of a computer program give


instructions to the computer.
• Instructions:
• Machine instructions are in binary code
• Instructions specify operations and memory cells involved
in the operation

Operation Address

0010 0000 0000 0100

0100 0000 0000 0101

0011 0000 0000 0110


Assembly Language

• A symbolic representation of the machine language of a


specific processor.
• Is converted to machine code by an assembler.
• Usually, each line of assembly code produces one machine
instruction (One‐to‐one correspondence).
• Programming in assembly language is slow and error‐prone
but is more efficient in terms of hardware performance.
• Mnemonic representation of the instructions and data
• Example:
Load Price
Add Tax
Store Cost
High‐level language
• A programming language which use statements consisting of
English‐like keywords such as "FOR", "PRINT" or “IF“, ... etc.
• Each statement corresponds to several machine language
instructions (one‐to‐many correspondence).
• Much easier to program than in assembly language.
• Data are referenced using descriptive names
• Operations can be described using familiar symbols
• Example:
Cost := Price + Tax
How to convert source program to application

Source Assembly
Program Compiler Language

Assembly Machine
Assembler
Language Language

36
Compiler
• Compiler: A compiler is a program that reads the 
source language and translates into an equivalent 
program into machine language.
– ‘C’ language
– ‘Pascal’ language
– FORTRAN language
– C++ language
– Java language

37
Interpretation
Source
Program

Interpreter Output

Input
• An interpreter is a computer program that translates 
and executes instructions written in a computer 
programming language line‐by‐line, unit by unit etc.,
• Example
– Console Commend, Matlab system
38
Compilation vs. Interpretation

• Compilation:
– Syntax errors caught before running the program
– Better performance
– Decisions made once, at compile time
• Interpretation:
– Better diagnostics (error messages)
– More flexibility
– Supports creation/modification of program code on 
the fly
Introduction to MATLAB
• MATLAB is a interpreter for doing numerical 
computation. It’s name is derived from MATrix
LABoratory.
MATLAB Desktop
Menu and toolbar

Workspace

History Command
How to learn Matlab

• Remember the help command
• MATLAB help pages:
– describe how to use functions and gives examples
– provides theory behind more complex functions
• Getting Started
• MATLAB Functions Listed by Category
• MATLAB Functions Listed Alphabetically
• Two good ebooks
– http://www.mathworks.com/moler/index.html

Você também pode gostar