algorithms 1up

Upload: chuah-chian-yeong

Post on 06-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Algorithms 1up

    1/14

    OutlineIntroduction

    ENGN2219 Computing for Engineering Simulation

    Algorithms

    Ramesh Sankaranarayana

    Research School of Computer ScienceAustralian National University

    Canberra, ACT

    ENGN2219 Computing for Engineering Simulation Algorithms 1 / 14

    http://goforward/http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    2/14

    OutlineIntroduction

    1 Introduction

    Problem - Spacecraft LaunchAlgorithmsProgramming Languages

    ENGN2219 Computing for Engineering Simulation Algorithms 2 / 14

    http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    3/14

    OutlineIntroduction

    Problem - Spacecraft LaunchAlgorithmsProgramming Languages

    Problem Statement

    Spacecraft Launch

    A reusable spacecraft, Space Ship One, is to be launched from amother ship at an altitude of 25, 000 feet. Assuming that thespacecraft uses all its fuel to achieve a vertical velocity u atlaunch, what is the value of u for the spacecraft to reach outerspace (an altitude of 100 km)?

    ENGN2219 Computing for Engineering Simulation Algorithms 3 / 14

    http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    4/14

    OutlineIntroduction

    Problem - Spacecraft LaunchAlgorithmsProgramming Languages

    Algorithms

    Definition

    Informally, an algorithm is a step-by-step procedure to solve aproblem. A recipe, as it were. There is no commonly accepted

    formal definition of an algorithm. We will use the following one byStone (1972):

    We define an algorithm to be a set of rules that precisely

    defines a sequence of operations such that each rule is

    effective and definite and such that the sequenceterminates in a finite time.

    ENGN2219 Computing for Engineering Simulation Algorithms 4 / 14

    P bl S f L h

    http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    5/14

    OutlineIntroduction

    Problem - Spacecraft LaunchAlgorithmsProgramming Languages

    Algorithms

    Definition

    He explains that:

    For people to follow the rules of an algorithm, the rules

    must be formulated so that they can be followed in arobot-like manner, that is, without the need for thought...

    however, if the instructions are to be obeyed by someone

    who knows how to perform arithmetic operations but

    does not know how to extract a square root, then we

    must also provide a set of rules for extracting a square

    root in order to satisfy the definition of algorithm.

    ENGN2219 Computing for Engineering Simulation Algorithms 5 / 14

    P bl S ft L h

    http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    6/14

    OutlineIntroduction

    Problem - Spacecraft LaunchAlgorithmsProgramming Languages

    Algorithms

    Definition

    and

    Not all instructions are acceptable, because they may

    require the robot to have abilities beyond those that weconsider reasonable.

    as well

    An intuitive definition of an acceptable sequence of

    instructions is one in which each instruction is precisely

    defined so that the robot is guaranteed to be able to

    obey it.

    ENGN2219 Computing for Engineering Simulation Algorithms 6 / 14

    Problem Spacecraft Launch

    http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    7/14

    OutlineIntroduction

    Problem - Spacecraft LaunchAlgorithmsProgramming Languages

    Algorithms

    Examples

    Print the first 100 positive integers.

    The long division algorithm.

    Maintaining an aircrafts altitude in flight.

    ENGN2219 Computing for Engineering Simulation Algorithms 7 / 14

    Problem Spacecraft Launch

    http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    8/14

    OutlineIntroduction

    Problem - Spacecraft LaunchAlgorithmsProgramming Languages

    Algorithms

    Representation

    FlowchartsPseudocode

    Natural language

    Programming language

    ENGN2219 Computing for Engineering Simulation Algorithms 8 / 14

    Problem - Spacecraft Launch

    http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    9/14

    OutlineIntroduction

    Problem Spacecraft LaunchAlgorithmsProgramming Languages

    Problem Statement

    Spacecraft Launch

    A reusable spacecraft, Space Ship One, is to be launched from amother ship at an altitude of 25, 000 feet. Assuming that thespacecraft uses all its fuel to achieve a vertical velocity u atlaunch, what is the value of u for the spacecraft to reach outerspace (an altitude of 100 km)?

    ENGN2219 Computing for Engineering Simulation Algorithms 9 / 14

    O liProblem - Spacecraft Launch

    http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    10/14

    OutlineIntroduction

    Problem Spacecraft LaunchAlgorithmsProgramming Languages

    Algorithms

    PseudocodecmsPerInch = 2.54 % from conversion tables

    inchesPerFt = 12 % from conversion tables

    metersPerCm = 1/100 % from conversion tables

    metersPerFt = metersPerCm * cmsPerInch *

    inchesPerFt

    g = 9.81 % m/sec^2

    finalAltitude = 100 % km. Given

    initialAltitude = 25000 % ft. Given.

    s = (finalAltitude * 1000) -

    (initialAltitude * metersPerFt)

    u = sqrt(2*g*s) % required initial velocity

    ENGN2219 Computing for Engineering Simulation Algorithms 10 / 14

    O tliProblem - Spacecraft Launch

    http://goforward/http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    11/14

    OutlineIntroduction

    pAlgorithmsProgramming Languages

    Architecture

    The Von Neumann Architecture

    memory

    ALU

    input/output

    control unit

    AC

    ENGN2219 Computing for Engineering Simulation Algorithms 11 / 14

    OutlineProblem - Spacecraft Launch

    http://goforward/http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    12/14

    OutlineIntroduction

    pAlgorithmsProgramming Languages

    Architecture

    Main components

    Central Processing Unit (CPU)

    Memory - main (RAM) and secondary (hard drives, flash

    cards, etc.)Bus - Data, Address and Control

    Program Counter (PC)

    Arithmetic and Logic Unit (ALU)

    Registers - instruction, status, index, accumulator

    Input/Output (I/O) Devices

    ENGN2219 Computing for Engineering Simulation Algorithms 12 / 14

    Outline Problem - Spacecraft Launch

    http://goforward/http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    13/14

    OutlineIntroduction

    AlgorithmsProgramming Languages

    Programming Languages

    GenerationsFirst generation - machine language. Processor dependent.Hard to program. Not portable.

    Second generation - assembly language. More like a symbolicversion of machine language. Easier to program, but still

    tedious. Examples - 8086 and PDP-11 assembly languages.

    Third generation - more similar to spoken language. Mucheasier to program. Much more portable. Examples - C,Fortran.

    Fourth generation - completely portable between supportedprocessor types. Each line of code produces significant amountof machine instructions. Examples - Java, Ada, C#, Matlab,SQL. Includes Domain Specific Languages like OCL, QVT,Eclipse Modeling Framework, grep, sed.

    ENGN2219 Computing for Engineering Simulation Algorithms 13 / 14

    Outline Problem - Spacecraft Launch

    http://goforward/http://find/http://goback/
  • 8/3/2019 Algorithms 1up

    14/14

    OutlineIntroduction

    AlgorithmsProgramming Languages

    Programming Languages

    Programming ParadigmsImperative - Also called procedural. Traditional approach. Asequence of commands that leads to the desired output.Examples - C, FORTRAN, COBOL and Ada.

    Declarative - Develop a precise statement of the problem,

    rather than an algorithm for solving the problem. Built on anunderlying general problem-solving algorithm. Formal logicprovides such an algorithm. Example - Prolog.

    Functional - Programs written as a bunch of functions.

    Recursion and nesting is natural in this approach. Example -Haskell.

    Object Oriented - The system is specified as a collection ofobjects and interactions between these objects. Examples -Simula, Smalltalk, Java, C++, C#.

    ENGN2219 Computing for Engineering Simulation Algorithms 14 / 14

    http://goforward/http://find/http://goback/