Вы находитесь на странице: 1из 4

# Introduction

Introduction

## ENGN2219 Computing for Engineering Simulation

Algorithms Ramesh Sankaranarayana
School of Computer Science Australian National University Canberra, ACT 1

Algorithms

1 / 14

## ENGN2219 Computing for Engineering Simulation

Algorithms

2 / 14

Outline Introduction

## Problem - Spacecraft Launch Algorithms Programming Languages

Outline Introduction

## Problem - Spacecraft Launch Algorithms Programming Languages

Problem Statement

Algorithms

Spacecraft Launch A reusable spacecraft, Space Ship One, is to be launched from a mother ship at an altitude of 25; 000 feet. Assuming that the spacecraft uses all its fuel to achieve a vertical velocity u at launch, what is the value of u for the spacecraft to reach outer space (an altitude of 100 km)?

De nition Informally, an algorithm is a step-by-step procedure to solve a problem. A recipe, as it were. No commonly accepted formal de nition of an algorithm. We will use the following one by Stone (1972):

We de ne an algorithm to be a set of rules that precisely de nes a sequence of operations such that each rule is e ective and de nite and such that the sequence terminates in a nite time.

Algorithms

3 / 14

## ENGN2219 Computing for Engineering Simulation

Algorithms

4 / 14

Introduction

Programming Languages

Introduction

Programming Languages

Algorithms
De nition He explains that:

Algorithms
De nition and

For people to follow the rules of an algorithm, the rules must be formulated so that they can be followed in a robot-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 de nition of algorithm.

Not all instructions are acceptable, because they may require the robot to have abilities beyond those that we consider reasonable. An intuitive de nition of an acceptable sequence of instructions is one in which each instruction is precisely de ned so that the robot is guaranteed to be able to obey it.

as well

Algorithms

5 / 14

## ENGN2219 Computing for Engineering Simulation

Algorithms

6 / 14

Outline Introduction

## Problem - Spacecraft Launch Algorithms Programming Languages

Outline Introduction

## Problem - Spacecraft Launch Algorithms Programming Languages

Algorithms

Algorithms

Examples Print the rst 100 positive integers. The long division algorithm. Maintaining an aircraft's altitude in ight.

Algorithms

7 / 14

## ENGN2219 Computing for Engineering Simulation

Algorithms

8 / 14

Introduction

Programming Languages

Introduction

Programming Languages

Problem Statement

Algorithms
Pseudocode
cmsPerInch = 2.54 % from conversion inchesPerFt = 12 % from conversion metersPerCm = 1/100 % from conversion metersPerFt = metersPerCm * cmsPerInch inchesPerFt g = 9.81 % m/sec^2 finalAltitude = 100 % km. Given initialAltitude = 25000 % ft. Given. tables tables tables *

Spacecraft Launch A reusable spacecraft, Space Ship One, is to be launched from a mother ship at an altitude of 25; 000 feet. Assuming that the spacecraft uses all its fuel to achieve a vertical velocity u at launch, what is the value of u for the spacecraft to reach outer space (an altitude of 100 km)?

## s = (finalAltitude * 1000) (initialAltitude * metersPerFt) u = sqrt(2*g*s) % required initial velocity

ENGN2219 Computing for Engineering Simulation Algorithms 9 / 14 ENGN2219 Computing for Engineering Simulation Algorithms

10 / 14

Outline Introduction

## Problem - Spacecraft Launch Algorithms Programming Languages

Outline Introduction

## Problem - Spacecraft Launch Algorithms Programming Languages

Architecture

Architecture
Main components Central Processing Unit (CPU) Memory - main (RAM) and secondary (hard drives, ash 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

memory

control unit

ALU AC

input/output

Algorithms

11 / 14

## ENGN2219 Computing for Engineering Simulation

Algorithms

12 / 14

Introduction

Programming Languages

Introduction

Programming Languages

Programming Languages
Generations First generation - machine language. Processor dependent. Hard to program. Not portable. Second generation - assembly language. More like a symbolic version of machine language. Easier to program, but still tedious. Examples - 8086 and PDP-11 assembly languages. Third generation - more similar to spoken language. Much easier to program. Much more portable. Examples - C, Fortran. Fourth generation - completely portable between supported processor types. Each line of code produces signi cant amount of machine instructions. Examples - Java, Ada, C#, Matlab, SQL. Includes Domain Speci c Languages like OCL, QVT, Eclipse Modeling Framework, grep, sed.
ENGN2219 Computing for Engineering Simulation Algorithms 13 / 14

Programming Languages
Programming Paradigms Imperative - Also called procedural. Traditional approach. A sequence 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 an underlying general problem-solving algorithm. Formal logic provides 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 speci ed as a collection of objects and interactions between these objects. Examples Simula, Smalltalk, Java, C++, C#.
ENGN2219 Computing for Engineering Simulation Algorithms

14 / 14