Chapter 1- Sahar PPT

22
1 Chapter 1

description

Intro to matlab

Transcript of Chapter 1- Sahar PPT

Page 1: Chapter 1- Sahar PPT

1

Chapter 1

Page 2: Chapter 1- Sahar PPT

Computer Hardware Computer Software

2

Computing Components

Internal Memory

ExternalMemory

Central Processing Unit

(CPU)

Input Devices

Output Devices

Hard-ware

Operating System

Windows, Linux, …

Application Software

Word, MATLAB, MATLAB programs

Page 3: Chapter 1- Sahar PPT

CORRECTNESS!!!Program outputs correct results for any instance of the problemDoes a program/software have to run correctly when you first build it? NOT NECESSARILYDoes it have to run correctly when you are ready to release/launch it?

YES!!3

Some characteristics of a “good” program

Page 4: Chapter 1- Sahar PPT

CORRECTNESS!!!What happens if you release a software that does not always work correctly?Word processor :

Unhappy customerFix the bugs and release a new versionNot a big deal?May be, but you might loose customers

4

Some characteristics of a “good” program

Page 5: Chapter 1- Sahar PPT

CORRECTNESS!!!What happens if you release a software that does not always work correctly?Banking system :

Very unhappy customerMost probably you will loose business

5

Some characteristics of a “good” program

Page 6: Chapter 1- Sahar PPT

CORRECTNESS!!!What happens if you release a software that does not always work correctly?Can a software problem cause loss of life?

YESExamples:Software controlling radiation therapyAir navigation system

6

Some characteristics of a “good” program

Page 7: Chapter 1- Sahar PPT

CORRECTNESS!!! EfficiencyMemory space and time needed to run the program

7

Some characteristics of a “good” program

Page 8: Chapter 1- Sahar PPT

CORRECTNESS!!! Efficiency Readability

◦ Coding style◦ Documentation

8

Some characteristics of a “good” program

Page 9: Chapter 1- Sahar PPT

A) Calculates and displays side length and area of squares of side length 1 up to 3

B) Displays the numbers between 1 and 3C) Multiplies 1 by 3 and displays the valueD) Calculates area of a rectangle with width

= 1 and length = 3

9

What does this code do?a=1; b=3;for index=a:b disp([index,index*index]); end

Page 10: Chapter 1- Sahar PPT

A) Calculates and displays side length and area of squares of side length 1 up to 3

B) Displays the numbers between 1 and 3C) Multiplies 1 by 3 and displays the valueD) Calculates area of a rectangle with width

= 1 and length = 3

10

What does this code do?min=1; max=3;for side=min:max area=side*side; disp([side,area]); end

Page 11: Chapter 1- Sahar PPT

CORRECTNESS!!! Efficiency Readability

◦ Coding style◦ Documentation◦ Readable code maintainable

11

Some characteristics of a “good” program

a=1; b=3;for index=a:b disp([index,index*index]); end

min=1; max=3; % loop displays square side length and area for % side length range from min to max for side=min:max area=side*side; disp([side,area]); end

GOOD

BAD

indentation

meaningful variable names

documentation

Page 12: Chapter 1- Sahar PPT

CORRECTNESS!!! Efficiency Readability Modular reusable

12

Some characteristics of a “good” program

Page 13: Chapter 1- Sahar PPT

13

An Engineering Problem-Solving Methodology

1. PROBLEM STATEMENT

2. INPUT/OUTPUT DESCRIPTION

3. HAND EXAMPLE

4. ALGORITHM DEVELOPMENT

5. IMPLEMENTATION

6. TESTING

A description of the problem with any constraints.

Page 14: Chapter 1- Sahar PPT

14

An Engineering Problem-Solving Methodology

1. PROBLEM STATEMENT

2. INPUT/OUTPUT DESCRIPTION

3. HAND EXAMPLE

4. ALGORITHM DEVELOPMENT

5. IMPLEMENTATION

6. TESTING

• Input: List of all values the user will specify • Output: List of a values to be computed by the

program

Page 15: Chapter 1- Sahar PPT

15

An Engineering Problem-Solving Methodology

1. PROBLEM STATEMENT

2. INPUT/OUTPUT DESCRIPTION

3. HAND EXAMPLE

4. ALGORITHM DEVELOPMENT

5. IMPLEMENTATION

6. TESTING

• Work through on paper one or more instances of the problem, Why?• supplies insight to the solution of the problem• supplies answers to be used to verify the program results

Page 16: Chapter 1- Sahar PPT

16

An Engineering Problem-Solving Methodology

1. PROBLEM STATEMENT

2. INPUT/OUTPUT DESCRIPTION

3. HAND EXAMPLE

4. ALGORITHM DEVELOPMENT

5. IMPLEMENTATION

6. TESTING

• An Algorithm is a step by step sequence of instructions which lead to the solution of a problem

• Usually written in pseudo code : List of statements (in English) which specify steps used in solving the problem.

Page 17: Chapter 1- Sahar PPT

17

An Engineering Problem-Solving Methodology

1. PROBLEM STATEMENT

2. INPUT/OUTPUT DESCRIPTION

3. HAND EXAMPLE

4. ALGORITHM DEVELOPMENT

5. IMPLEMENTATION

6. TESTING• Translation of an algorithm into a programming

language MATLAB

Page 18: Chapter 1- Sahar PPT

18

An Engineering Problem-Solving Methodology

1. PROBLEM STATEMENT

2. INPUT/OUTPUT DESCRIPTION

3. HAND EXAMPLE

4. ALGORITHM DEVELOPMENT

5. IMPLEMENTATION

6. TESTING• Executing the program multiple times, with different data and

checking the results against the expected answers.• If errors are detected, incorrect statement must be found and fixed

Page 19: Chapter 1- Sahar PPT

Problem Statement:Given the following information about the trips of two travelers A and B, , determine who is traveling at a higher speed

A traveled x miles in m hours B traveled y miles in n hours

Input and Output:Input:

Distance traveled by A (distanceA, x in the above statement)Time taken by A (timeA, m in the above statement)Distance traveled by A (distanceB, y in the above statement)Time taken by A (timeB, n in the above statement)

Output:Traveler with higher speed (fasterTraveler)

19

Problem Solving Methodology, Example1

Page 20: Chapter 1- Sahar PPT

Hand Example:distanceA = 100 mtimeA = 2 hrdistanceB = 70 mtimeB = 1 hrspeedA = 100 / 2 = 50speedB = 70 / 1 = 70fasterTraveler is B

Algorithm:Compute speedA

speedA = distanceA/timeACompute speedB

speedB = distanceB/timeBCompare speedA and speedB and output traveler

with higher speed if speedA > speedB output A

if speedA < speedB output B if speedA = speedB output TIE

20

Problem Solving Methodology, Example 1

Page 21: Chapter 1- Sahar PPT

We want to develop a database for proteins and peptides molecular composition and weight

21

Problem Solving Methodology, Example 2

https://doctorgrasshopper.wordpress.com/2010/10/

Page 22: Chapter 1- Sahar PPT

Example Protein Sequence (as a string of amino acid codes)

MRHIAHTQRCLSRLTSLVALLLIVLPMVFSPAHSC

GPGRGLGRHRARNLYPLVLKQTIPNLSEYTNSASG

PLEGVIRRDSPKFKDLVPNYNRDILFRDEEGTGAD

RLMSKRCKEKLNVLAYSVMNEWPGIRLLVTESWDE

DYHHGQESLHYEGRAVTIATSDRDQSKYGMLARLA

VEAGFDWVSYVSRRHIYCSVKSDSSISSHVHGCFTP

ESTALLESGVRKPLGELSIGDRVLSMTANGQAVYSE

VILFMDRNLEQMQNFVQLH

22

Amino Acid Code Chemical FormulaMolecular

Weight

Isoleucine I C6H13NO2 131.1736

Leucine L C6H13NO2 131.1736

Lysine K C6H14N2O2 146.1882

Methionine M C5H11NO2S 149.2124

Phenylalanine F C9H11NO2 165.19

Threonine T C4H9NO3 119.1197

Tryptophan W C11H12N2O2 204.2262

Valine V C5H11NO2 117.1469

Arginine R C6H14N4O2 174.2017

Histidine H C6H9N3O2 155.1552

Alanine A C3H7NO2 89.0935

Asparagine N C4H8N2O3 132.1184

Aspartate D C4H7NO4 133.1032

Cysteine C C3H7NO2S 121.159

Glutamate E C5H9NO4 147.1299

Glutamine Q C5H10N2O3 146.1451

Glycine G C2H5NO2 75.0669

Proline P C5H9NO2 115.131

Serine S C3H7NO3 105.093

Tyrosine Y C9H11NO3 181.1894