+ All Categories
Home > Documents > Es 314 Programming, simulation and modeling

Es 314 Programming, simulation and modeling

Date post: 03-Jan-2016
Category:
Upload: burke-sanford
View: 19 times
Download: 1 times
Share this document with a friend
Description:
Es 314 Programming, simulation and modeling. lecture: M W 3 – 4:50 PM 2008, Salazar Hall. Course web site. http://ravi.cs.sonoma.edu/es314fa10 this year’s web site is not functional yet, but take a look at last year’s web site: http://ravi.cs.sonoma.edu/es314fa09. - PowerPoint PPT Presentation
41
Es 314 Programming, simulation and modeling lecture: M W 3 – 4:50 PM 2008, Salazar Hall
Transcript
Page 1: Es 314 Programming, simulation and modeling

Es 314Programming, simulation

and modeling

lecture:M W 3 – 4:50 PM

2008, Salazar Hall

Page 2: Es 314 Programming, simulation and modeling

Course web site http://ravi.cs.sonoma.edu/es314fa10this year’s web site is not functional yet, but take a

look at last year’s web site: http://ravi.cs.sonoma.edu/es314fa09

Page 3: Es 314 Programming, simulation and modeling

Catalog Description of the course:

Lecture: 4 hours; laboratory: 0 hours. Pointers and dynamic allocation of storage; linked lists; an introduction to the object oriented programming (OOP) paradigm; classes and objects; encapsulation; member variables and member functions. Static arrays, dynamic arrays, stacks and queues, linked lists, hashing. System modeling techniques and applications such as generation of noise (random numbers) and correlated signal with different pdfs, measurement of statistical parameters like moments, queuing systems and system simulation.

Prerequisite: CS 115: Programming I. Co-requisites: MATH 345: Probability Theory and ES 220: Electric Circuits, or consent of instructor.

Page 4: Es 314 Programming, simulation and modeling

Goals of the course: To introduce software design for engineering applications through MATLAB programming, computational modeling of physical systems and software simulation of simple physical systems. Specifically, the following topics will be covered:•MATLAB programming – iteration, library and user-defined functions, scripts, structured data and objects, image and audio files, plotting and visualization, recursion, project design and development.•performing statistical analyses of datafundamental algorithms for sorting, searching, solving system of equations etc.•computational modeling•simulation of physical systems and models

Page 5: Es 314 Programming, simulation and modeling

Text book

Kaplan, Daniel T. Introduction to Scientific Computation and Programming, Brooks/Cole-

Thomson Learning, 2004.

http://www.macalester.edu/~kaplan/ScientificProgramming/index.html

We will cover most of Chapters 1 to 12.

For simulation and modeling, we will use other sources.

Page 6: Es 314 Programming, simulation and modeling

course overview

•Matlab programming

• simulation and modeling

• case studies• database, graphics and plotting, audio, image processing, modeling of biosignals etc.

• new this semester: final project – each student will choose one problem to work on.

Page 7: Es 314 Programming, simulation and modeling

course overview

•Matlab programming

• simulation and modeling

• case studies• database, graphics and plotting, user interface design, stochastic modeling, queuing and network models, audio signal processing, image and video processing, modeling of biosignals etc.

Page 8: Es 314 Programming, simulation and modeling

Matlab programming language• most widely used by (Electrical) engineers

• other similar ones: mathematica, maple, mathcad, macsyma

• vector and matrix centered. (Name comes from MATrix LABoratory). Very high level operations for processing vectors and matrices.

• extensive support for mathematical operations, plotting, visualization, user interface design

• library functions for mathematical operations (solving equations etc.)

• toolboxes: signal processing, wavelets etc.

Page 9: Es 314 Programming, simulation and modeling

Matlab programming language

Why useful for engineering applications

• rich numeric/image library functions

• very useful for displaying, visualizing data

• high-level: focus on algorithm structure,

not on low level details (especially for

vector, matrix …)•Much smaller code size compared to others

• allows quick prototype development

• interfacing with other languages and

systems

Page 10: Es 314 Programming, simulation and modeling

User interface

• interactive mode

• result appears immediately after the command is entered

• interpreted language

• scripts for sequence of operations, programs

• save scripts as files with .m extension

Page 11: Es 314 Programming, simulation and modeling

Main features of Matlab

•simple data types:• numbers, characters, string, boolean

•structured types:• vector, matrix, indexing, mixed data types

• files and scripts:

Page 12: Es 314 Programming, simulation and modeling

Main features of Matlab

• functions:• user defined functions• more advanced support for functions

• conditionals:• if statement, if … then .. else, switch statement

• loops:• for loop, nested loop, loop termination, conditional loop

Page 13: Es 314 Programming, simulation and modeling

Main features of Matlab

• scope:• environment and scope• resolving name conflicts

• events:• reactive program• user interface design

Page 14: Es 314 Programming, simulation and modeling

tutorials

• http://www.mathworks.com/ has links to tutorials, video clips on various topics http://www.youtube.com/user/MATLAB

• tutorials from educators• http://www.math.utah.edu/lab/ms/matlab/matlab.html • http://amath.colorado.edu/computing/Matlab/Tutorial/ • http://www.math.utah.edu/lab/ms/matlab/matlab.html

• numerous other tutorials (engineering design)

Page 15: Es 314 Programming, simulation and modeling

Grading

short quizzes: 5 to 10 points The quizzes will be in-class for a duration to 10 to 15 minutes, one for each class.

programming assignments and projects: 40 points Most of the assignments will involve problem solving and implementing the solution using MATLAB. There will be a final project chosen by each student individually.

mid-semester tests (2): 20 to 25 points in-class, may or may not be open book (depending on your choice). final examination: 20 to 25 points This exam will be in-class and comprehensive. It will take place at the time scheduled by registrar’s office. You can find out from the web page: http://www.sonoma.edu/ university/classsched/finals_sched.pdf

Page 16: Es 314 Programming, simulation and modeling

Stochastic models – example

What is the probability that a web page is visited?

Model: each web page is represented by a node and each link from page A to page B is an edge in the graph. Assume a visitor to a page will randomly click on one of the links on the page.

Also assume that one starts with probability 1/n at any page (where n = total number of pages).

This model is called a Markov chain.

Page 17: Es 314 Programming, simulation and modeling

Markov chain – simulation

Shown below is a simple Markov chain. What is the average number of steps it takes to move from state 1 to state 3?

1 32

Assume all outgoing arcs have the same probability

Application: assuming that the server has probability = 0.55 of winning a game, what is the average length of a game in tennis?

Page 18: Es 314 Programming, simulation and modeling

signal generation and display – simple example

Page 19: Es 314 Programming, simulation and modeling

signal generation and display – simple example

Page 20: Es 314 Programming, simulation and modeling

Image models

2-d image: Digital image is represented by a collection of pixels. Each pixel has a color value represented by 32 bits. (R, G, B, A) values.

Digital images can be processed in various ways:

• compression

• restoration, de-blurring

• enhancement, noise reduction

Page 21: Es 314 Programming, simulation and modeling

Image processing

original image restored image

deblurring

Page 22: Es 314 Programming, simulation and modeling

Image merging

input

output

Page 23: Es 314 Programming, simulation and modeling

Image merging – a more complex example

Input images

output

Example taken from http://www.graficaobscura.com/merge/index.html

Page 24: Es 314 Programming, simulation and modeling

Volume Data Representation and Visualization

Typical scalar volume data is composed of a 3-D array of data and three coordinate arrays of the same dimensions. The

coordinate arrays specify the x-, y-, and z-coordinates for each data point.

For example, flow data might have coordinate units of inches and data units of psi.

A number of MATLAB functions are useful for visualizing scalar data:• Slice planes provide a way to explore the distribution of data values within the volume by mapping values to colors. • You can orient slice planes at arbitrary angles, as well as use nonplanar slices. You can specify the data used to color isosurfaces, enabling you to display different information in color and surface shape• Contour slices are contour plots drawn at specific coordinates within the volume. Contour plots enable you to see where in a given plane the data values are equal.

Page 25: Es 314 Programming, simulation and modeling

MRI Data Visualization

• MRI data typically contains a number of slice planes taken through a volume, such as the human body.

• MRI data formats that can be accessed directly through Matlab:

•A series of 2-D images representing slices through the head•2-D and 3-D contour slices taken at arbitrary locations within the data•An isosurface with isocaps showing a cross section of the interior.

Page 26: Es 314 Programming, simulation and modeling

contour slices

Example taken from: http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab.html&http://www.cs.dartmouth.edu/farid/

teaching/cs136/summer.08/

Page 27: Es 314 Programming, simulation and modeling
Page 28: Es 314 Programming, simulation and modeling

Matlab – working windows

Page 29: Es 314 Programming, simulation and modeling

Matlab – Introduction (Ch 2)•Variables:

Page 30: Es 314 Programming, simulation and modeling

Variable definition

• need not be declared

• Variable names can contain up to 63

characters

• Variable names must start with a letter

followed by letters, digits, and underscores.

• Variable names are case sensitive.

• Key words can’t be used as variable names.

(Key words list is in the next slide.)

Page 31: Es 314 Programming, simulation and modeling

Matlab Special Variables

• ans Default variable name for results• pi: Value of π >> pi

ans =

3.14159265358979

• eps: smallest incremental number• inf: Infinity• NaN: Not a number e.g. 0/0• realmin: The smallest usable positive real number• realmax: The largest usable positive real number

Page 32: Es 314 Programming, simulation and modeling

Matlab – Introduction (Ch 2)

• key words:• if, else, end, for, while, break, switch, case, try, catch, return, global, function, persistent etc.

• arithmetic operations: + – * (or .*) latter used for component-wise * in vector / (or ./) \ (or .\) ^ (or .^) a^b stands for ab

Page 33: Es 314 Programming, simulation and modeling

Other MATLAB symbols

>> prompt. . . continue statement on next line, separate statements and data% start comment which ends at end of line; (1) suppress output

(2) used as a row separator in a matrix

: specify range

Page 34: Es 314 Programming, simulation and modeling

Matlab – Introduction (Ch 2)

• Exercise 2.1: Evaluate the expression

3 – 5 + 4/6 – 8 *4^2

• Exercise 2.2: Write (3 – (5 + 2* 8))/4 in functional style using plus, minus, times and rdivide.

a + b is written as plus (a, b) in functional style.

Page 35: Es 314 Programming, simulation and modeling

some helpful commands

>> whos Lists all the variables currently active in

environment >> lookfor <word> gives all sentences

containing <word> in the manual.

Use up arrow to repeat the previous command.

>> help

Page 36: Es 314 Programming, simulation and modeling

Chapter 3 – numbers, string, booleans

integer:

MATLAB stores numeric data as double-precision floating point (double) by default. To store data as an integer, you need to convert from double to the desired integer type.

Example: To store  325 as a 16-bit signed integer assigned to variable x:

>> x = int16(325);

If the number being converted to an integer has a fractional part, MATLAB rounds to the nearest integer.

Page 37: Es 314 Programming, simulation and modeling

• If the fractional part is exactly 0.5, then from the two equally nearby integers, MATLAB chooses the one for which the absolute value is larger in magnitude:

>> x = 325.499; >> int16(x) ans = 325>> x = x + .001; >> int16(x) ans = 326

Built-in functions that convert to int

• Other related functions: floor, ceil

Page 38: Es 314 Programming, simulation and modeling

long floating-point format

>> format long>> x = 1.5^2.3;>> x

x =

2.54103060477792

>> format short>> x

x =

2.5410

>> x = 2.564593653;>> x

x =

2.5646

>>

Page 39: Es 314 Programming, simulation and modeling

Complex numbers

Page 40: Es 314 Programming, simulation and modeling

Strings

Character: alphabetical – upper/lower (‘a’ .. ‘z’, ‘A’ .. ‘Z’) digits – 0, 1, …, 9 special characters - $, % etc. control characters - \n (end of line) etc.

Each character is encoded by 8 bits (ASCII) or 16 bits (unicode)

Unicode allows encoding of alphabets from many languages such as Hungarian, Chinese, Swahili etc.

String - sequence of characters.

>> greeting = ‘hello’

Page 41: Es 314 Programming, simulation and modeling

String operations

>> length(word)

ans = 5

>> strcmp(word, ‘hello!’)

ans = 0

1 if the Boolean expression is true, 0 else.

Strcmp compares two strings.


Recommended