Matlab Lecture

40
Advanced Mathematical Methods for Civil Engineering Applications Wonsiri Punurai, PhD Wonsiri Punurai, PhD Department of Civil Engineering Room 6391, EG Building 3 Faculty of Engineering, Mahidol University Personal Web: www.egmu.net/~civil/wonsiri

description

Matlab Lecture

Transcript of Matlab Lecture

Advanced Mathematical Methods for Civil Engineering Applications

Wonsiri Punurai, PhDWonsiri Punurai, PhD

Department of Civil EngineeringRoom 6391, EG Building 3

Faculty of Engineering, Mahidol UniversityPersonal Web: www.egmu.net/~civil/wonsiri

Course Information

Introduction to computer applications in civil engineering. Emphasis on analysis, mathematical problem-solving skills with computer tools and hand techniques.

Course Goals

At the end of this course, students will be able toUse, create, and modify scripts in MATLAB (and probably spreadsheets in MS EXCEL) to solve quantitative simple problems in future classes.Prepare oral + written presentations in class

Conduct of Course

Homework/Projects/Quizzes 30 %

Midterm Exam 30 %

Final Exam 40 %

Warnings!!

Participation expected, check by quizzesStudy in groups but submit work on your ownNo Copying of Matlab codeSubmit Homework at the beginning of classLate homework with penaltyNo make up quizzes or exams

Computers as engineering tools

Productivity– One engineer can do the work for “many”.

Precision– If use properly computers offer solutions to many

engineering problemsBetter communication– Visualization

Lecture I- Introduction to MATLAB

What is MATLAB?

Reference: www.mathworks.com

MATLAB 101

Getting Started ( เริ่มแรกเขาโปรแกรม )

Basic Arithmetic ( คําสั่งที่ใชในการคํานวณทางคณิตศาสตร )

Built-in Functions ( คําสั่งทางคณิตศาสตรที่มากับโปรแกรม )

Built-in Variables ( ลักษณะของตัวแปรที่มากับโปรแกรม )

Getting Started

MATLAB101MATLAB101MATLAB101---Getting StartedGetting StartedGetting Started

Launch Pad

Command Window

Command History

MATLAB101MATLAB101MATLAB101---Getting StartedGetting StartedGetting Started

MATLAB101MATLAB101MATLAB101---Getting StartedGetting StartedGetting Started

MATLAB101MATLAB101MATLAB101---Getting StartedGetting StartedGetting Started

MATLAB101MATLAB101MATLAB101---Getting StartedGetting StartedGetting Started

MATLAB101MATLAB101MATLAB101---Getting StartedGetting StartedGetting Started

MATLAB101MATLAB101MATLAB101---Getting StartedGetting StartedGetting Started

Basic Arithmetic

Calculator functions work as you’d expect:

+ and - are addition, / is division, * is multiplication, ^ is an exponent.

MATLAB101MATLAB101MATLAB101---Basic ArithmeticBasic ArithmeticBasic Arithmetic

Basic Arithmetic (cont.)

MATLAB101MATLAB101MATLAB101---Basic ArithmeticBasic ArithmeticBasic Arithmetic

MATLAB101MATLAB101MATLAB101---Basic ArithmeticBasic ArithmeticBasic Arithmetic

MATLAB101MATLAB101MATLAB101---Basic ArithmeticBasic ArithmeticBasic Arithmetic

MATLAB101MATLAB101MATLAB101---Basic ArithmeticBasic ArithmeticBasic Arithmetic

MATLAB 102

Array/Matrix ( เมตริกซ )

How to save & load data ( การเรียกใชและบันทึกขอมลู )

Low level input & output

Graphics

Array/Matrix

A matrix is a rectangular array of numbers.Scalars = 1x1 matricesVectors = row x column matrices

LetLet’’s try create a matrix s try create a matrix ““AA”” here!!here!!

MATLAB102MATLAB102MATLAB102---ArrayArrayArray

Steps to create a matrix

Separate the elements of a row with blanks or commas.

Use a semicolon, ; , to indicate the end of each row.

Surround the entire list of elements with square brackets, [ ] .

MATLAB102MATLAB102MATLAB102---ArrayArrayArray

To check array dimension (no. of rows and columns) use a commandTo check array dimension (no. of rows and columns) use a command ““whoswhos””

MATLAB102MATLAB102MATLAB102---ArrayArrayArray

MATLAB102MATLAB102MATLAB102---ArrayArrayArray

MATLAB102MATLAB102MATLAB102---ArrayArrayArray

MATLAB102MATLAB102MATLAB102---ArrayArrayArray

MATLAB102MATLAB102MATLAB102---ArrayArrayArray

Quiz I

Compute Y = Ab;

Solution

MATLAB102MATLAB102MATLAB102---ArrayArrayArray

Save & Load Data

MATLAB102MATLAB102MATLAB102---Save/Load DataSave/Load DataSave/Load Data

MATLAB102MATLAB102MATLAB102---In/OutputIn/OutputIn/Output

Input/Output Functions

MATLAB102MATLAB102MATLAB102---In/OutputIn/OutputIn/Output

Graphics

First, making a window for graphics output by typing

Simply type “plot” in command window.The plot function has different forms, depending on input arguments.

Graphics (cont.)

Graphics – create multiple data sets in one graph

MATLAB has ability to create multiple graphs.

Graphics – specify line styles and colors

LetLet’’s try this!!s try this!!

Graphics – multiple plots in one figure

barplot loglog plot

semilog plot

Graphics – plotting examples

stair plot

Quiz II

Given y =sin (x1.8) where 0<x<0.5 and x increments every 0.05, try plotting graph between x and y values now!!