CZ1102 Computing & Problem Solving Lecture 1

Embed Size (px)

Citation preview

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    1/42

    IntroductiontoCZ1102

    1

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    2/42

    Objectiveof

    the

    module

    preparethestudenttoapproachproblemsolvinginanalgorithmicway,withanemphasisoncomputational

    aspect.

    Inparticular,elementsandpracticalitiesofcomputerprogrammingthroughthehighlevelmathematical

    computing

    environment

    will

    be

    incorporated

    in

    the

    coursestructure.

    Thisisanintensivehandsoncourseoncomputationalproblemsolvingwithmanypracticals.Majortopics:

    Fundamentalsof

    programming

    language.

    Arrays

    and

    structures.Functionsandfiles.ComputingusingMATLAB.

    2

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    3/42

    Detailedsyllabus

    Fundamentalsofprogramminglanguage

    computer

    components

    and

    software

    HierarchyintroductiontoMatlab

    programdesignanddevelopment

    datatypes

    and

    memory

    allocation

    relationaloperatorsandlogicalvariables

    conditionalstatement

    loopsswitchstructure

    3

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    4/42

    (cont)

    Arraysandstructures

    vector,

    matrix

    and

    multidimensional

    arrayselementaccessoperations

    recordandstructurearrays

    manipulatingof

    data

    of

    different

    types

    setoperations

    4

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    5/42

    (cont)

    Functionsandfiles

    elementary

    mathematical

    functionsuserdefinedfunctions

    argumentsandreturnvalues

    stringhandling

    readingandwritingdatafiles

    basicparadigmsonprogramdebugging

    5

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    6/42

    (cont)

    ComputingusingMATLAB

    elementarylinearalgebraoperations

    workingwithMfiles:functionsandscripts

    polynomialmultiplicationandrootfindingbybisection

    2Dand3Dfunctionplotting

    datafittingandinterpolation

    multidimensionaldatavisualization

    Codevecterization forcomputingefficiency

    lookforwardtootherprogramminglanguages:CandC++

    6

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    7/42

    References

    Onlinehelpresources

    http://www.mathworks.com/help Ebooks

    http://www.mathworks.com/moler/index.html

    BookBrianH.andD.Valentine,EssentialMATLABfor

    scientistsandengineers,AcademicPress,ISBN13:

    9780123748836.

    7

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    8/42

    Timetable

    Lecture

    Monday Tutorial (oddweek)

    1. Wed.

    2. Fri.1. Lab(evenweek)

    1. Wed.

    2. Fri.

    8

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    9/42

    Assessment

    Tutorial&Lab

    20% Twoprojects

    20%

    Groupproject

    (two

    members

    each)

    Finalexam(2A4sizehelpsheets)

    60%

    9

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    10/42

    Computerandprogramming

    10

    Lecture1

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    11/42

    Acomputer

    system

    11

    Printer(output)

    Monitor(output)

    Speaker(output)

    Scanner(input)

    Mouse(input)

    Keyboard(input)

    System unit

    (processor, memory)

    Storage devices

    (CD-RW, Floppy,Hard disk, zip,)

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    12/42

    WhatDoes

    A

    Computer

    Do?

    Computers can perform four general operations,which comprise the information processing cycle.

    Input

    Process

    Output Storage

    12

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    13/42

    Dataand

    Information

    All computer processing requires data, which is a

    collection of raw facts, figures and symbols, such asnumbers, 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, anduseful.

    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

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    14/42

    WhyComputer

    is

    important

    Theability

    to

    perform

    the

    information

    processing

    cyclewithamazingspeed.

    Reliability(lowfailurerate).

    Accuracy. Abilitytostorehugeamountsofdataand

    information.

    Abilityto

    communicate

    with

    other

    computers.

    14

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    15/42

    HowDoes

    aComputer

    Know

    what

    to

    do?

    Itmustbegivenadetailedlistofinstructions,

    calledacomputeprogram orsoftware,thattellsitexactlywhattodo.

    Beforeprocessingaspecificjob,thecomputer

    programcorresponding

    to

    that

    job

    must

    be

    stored

    inmemory.

    Oncetheprogramisstoredinmemorythe

    computecan

    start

    the

    operation

    by

    executing

    the

    programinstructionsoneaftertheother.

    15

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    16/42

    WhatAre

    The

    Primary

    Components

    Of

    A

    Computer?

    Inputdevices.

    CentralProcessingUnit

    controlunit

    arithmetic/logicunit.

    Memory.

    Outputdevices.

    Storagedevices.

    16

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    17/42

    InputDevices

    Keyboard.

    Mouse.

    17

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    18/42

    TheCentral

    processing

    Unit

    Thecentralprocessingunit(CPU)containselectroniccircuitsthatcauseprocessingtooccur.TheCPU

    interpretsinstructionstothecomputer,performsthelogicalandarithmeticprocessingoperations,and

    causestheinputandoutputoperationstooccur.Itis

    consideredthe

    brain of

    the

    computer.

    18

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    19/42

    Memory Memory also called Random Access Memory or RAM

    (temporary memory) is the main memory of the

    computer. It consists of electronic components thatstore 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 etchedon a chip that has startup directions for yourcomputer. It is permanent memory.

    19

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    20/42

    AmountOf

    RAM

    In

    Computers

    The amount of memory in computers is typicallymeasured 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 canstore approximately 8 million characters. One

    megabyte can hold approximately 500 pages of textinformation.

    20

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    21/42

    Output devices make the information resulting from theprocessing available for use.

    printercomputer screen.

    The printer produces a hard

    copy of your output

    computer screen producesa soft copy of your output.

    21

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    22/42

    StorageDevices

    Auxiliarystoragedevicesareusedtostoredatawhentheyarenotbeingusedinmemory.Themost

    commontypes

    of

    auxiliary

    storage

    used

    on

    personal

    computersare

    floppydisks (hardtoseenow)

    harddisks

    CDROMdrives.

    22

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    23/42

    HardDisks

    Consists of one or more rigid metal plates coatedwith 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 (onebillion bytes are called a gigabyte).

    23

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    24/42

    CompactDiscs

    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

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    25/42

    How

    computer

    is

    able

    to

    interact

    with

    users

    Computersoftware

    Systemsoftware

    Applicationsoftware.

    25

    Machine w ith all its hardware

    System Software

    Compilers, Interpreters, linker etc.Operating System, Device Drivers

    Application P rogramsWord-Processors, Spreadsheets, etc

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    26/42

    (cont) Systemsoftware

    Programswrittenforcomputersystems

    Example:

    OperatingSystems,

    Compiler,Loader,Linker,Interpreter.

    Applicationprograms

    Programswrittenforcomputerusers

    Example

    Office

    Webbrowser

    26

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    27/42

    System Software: Operating

    System OperatingSystemisasoftware,whichmakesa

    computertoactuallywork.

    OSacts

    as

    an

    interface

    between

    the

    application

    programsandthemachinehardware.

    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

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    28/42

    How

    to

    run

    a

    program

    on

    OS Steps that the computer goes through to run a

    program:

    28

    Memory

    Program Output

    Machine languageprogram

    (executable file)

    Data enteredduring execution

    Computed results

    C P U

    Input Data

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    29/42

    Program

    Execution

    in

    CPU StepstakenbytheCPUtorunaprogram

    (instructionsareinmachinelanguage):

    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

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    30/42

    How

    to

    develop

    an

    application Application(executablecode)isdevelopedbasedon

    sourceprograms(sourcecode)

    Twoapproaches

    Compilation

    Interpretation

    30

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    31/42

    Compilation Application(executablecode)isdevelopedbasedon

    sourceprograms(sourcecode)

    Sourceprogramsarewritteninprogramminglanguages

    PL=programminglanguage

    A PLis

    Aspecialpurposeandlimitedlanguage

    Asetofrulesandsymbolsusedtoconstructacomputer

    program

    Alanguageusedtointeractwiththecomputer

    31

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    32/42

    Computer

    Languages Machine Language

    Uses binary code

    Machine

    dependent Not portable

    Assembly LanguageUses mnemonics

    Machine

    dependentNot usually portable

    HighLevel Language (HLL)Uses Englishlike language

    Machine independentPortable (but must be compiled for different platforms)Examples: Pascal, C, C++, Java, Fortran, matlab, etc

    32

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    33/42

    MachineLanguage

    Operation Address

    0010 0000 0000 0100

    0100 0000 0000 0101

    0011 0000 0000 0110

    The representation of a computer program giveinstructions to the computer.

    Instructions: Machine instructions are in binary code Instructions specify operations and memory cells involved

    in the operation

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    34/42

    AssemblyLanguage

    A symbolic representation of the machine language of aspecific processor.

    Is converted to machine code by an assembler. Usually, each line of assembly code produces one machine

    instruction (Onetoone correspondence).

    Programming in assembly language is slow and errorprone

    but is more efficient in terms of hardware performance. Mnemonic representation of the instructions and data Example:

    Load Price

    Add TaxStore Cost

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    35/42

    High

    level

    language A programming language which use statements consisting of

    Englishlike keywords such as "FOR", "PRINT" or IF, ... etc.

    Each statement corresponds to several machine languageinstructions (onetomany 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

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    36/42

    How

    to

    convert

    source

    program

    to

    application

    36

    Compiler

    Assembler

    Source

    Program

    Assembly

    Language

    Assembly

    LanguageMachine

    Language

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    37/42

    Compiler Compiler:Acompilerisaprogramthatreadsthe

    sourcelanguageandtranslatesintoanequivalent

    programinto

    machine

    language.

    Clanguage

    Pascallanguage

    FORTRANlanguage

    C++language

    Javalanguage

    37

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    38/42

    Interpretation

    Aninterpreter isacomputerprogramthattranslatesandexecutesinstructionswritteninacomputer

    programminglanguagelinebyline,unitbyunitetc.,

    Example

    ConsoleCommend,Matlab system

    38

    Interpreter

    Source

    Program

    Input

    Output

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    39/42

    Compilationvs.Interpretation

    Compilation:

    Syntax

    errors

    caught

    before

    running

    the

    programBetterperformance

    Decisionsmadeonce,atcompiletime

    Interpretation:Better

    diagnostics

    (error

    messages)

    Moreflexibility

    Supportscreation/modificationofprogramcodeon

    thefly

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    40/42

    Introduction

    to

    MATLAB MATLABisainterpreterfordoingnumerical

    computation.ItsnameisderivedfromMATrix

    LABoratory.

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    41/42

    MATLABDesktop

    Menu and toolbar

    CommandHistory

    Workspace

  • 8/8/2019 CZ1102 Computing & Problem Solving Lecture 1

    42/42

    How

    to

    learn

    Matlab

    Rememberthehelp command

    MATLAB

    help

    pages:describehowtousefunctionsandgivesexamples

    providestheorybehindmorecomplexfunctions

    GettingStarted

    MATLABFunctionsListedbyCategory

    MATLABFunctionsListedAlphabetically

    Twogoodebooks

    http://www.mathworks.com/moler/index.html