Numerical Methods For Civil Engineers
Numerical Methods For Civil Engineers
Lecture 1 -
MATLAB
Introduction
Instructor: Mongkol JIRAVACHARADET
Institute of Engineering
Textbook
Applied Numerical Methods
With MATLAB for Engineers
and Scientists
STEVEN C. CHAPRA
Topics Covered
Introduction to Matlab Interpolation
Curve Fitting
Conduct of Course
Homework/Projects/Quizzes 30 %
Midterm Exam 30 %
Final Exam 40 %
Grading Policy
Final Score Grade
100 - 90 A
89 - 85 B+
84 - 80 B
79 - 75 C+
74 - 70 C
69 - 65 D+
64 - 60 D
59 - 0 F
WARNINGS !!!
1) Participation expected, check by quizzes
MATLAB
The Language of Technical Computing
M ATLAB
MATLAB
www.mathworks.com
MATLAB = MATrix LABoratory
- Math and computation
- Algorithm development
http://www.math.utah.edu/lab/ms/matlab/matlab.html
http://www.math.mtu.edu/~msgocken/intro/intro.html
MATLAB 1
- Getting started
- Basic Arithmetic
- Built-in Functions
- Built-in Variables
Development Environment: set of tools and facilities that help you use MATLAB
functions and files. Many of these tools are graphical user interfaces. It includes the
MATLAB desktop and Command Window, a command history, an editor and
dedugger, and browsers for viewing help, the workspace, files, and the search path.
Graphics: MATLAB has extensive facilities 2-D and 3-D data visualization,
animation, and presentation graphics.
The MATLAB Application Program Interface (API): allows you to write C and
Fortran programs that interact with MATLAB.
Getting Started
MATLAB Desktop
Getting Started
Command Window
Editor/Debugger
Basic Arithmetic
Calculator functions work as you'd expect:
>>(1+4)*3
ans =
15
+ and - are addition, / is division, * is multiplication, ^ is an exponent.
>> 5*5*5
>> 5^(-2.5)
>> 3*(23+14.7-4/6)/3.5
Built-in Functions
>> x = 5;
>> y = sqrt(59);
>> z = log(y) + x^0.25
z =
3.5341
The commas allow more than one command
on a line:
>> t = 5;
>> t = t + 2
t =
7
Variable Meaning
Arrays Operations
>> A = [ 3 5 7 9 11 ] >> A / B
>> A(3) >> A ./ B
>> length(A) >> A .^ 2
>> clear(A) >> odd = 1:2:11
>> B = [ 2 4 6 8 10 ] >> even = 2:2:12
>> A + B >> natural = 1:6
>> A - B >> angle = 0:pi/10:pi;
>> A * B >> sin(angle)
>> A .* B
Generate matrices using built-in functions
Subscripts
For example, A(4,2) is the number in the fourth row and second column.
>> A(4,2)
ans =
15
Submatrix
>> A(1,:)
>> A(:,2)
>> A(3:4,1:2)
Juxtaposition
>> B = [9 8 2 5 ; 4 5 6 7 ; 2 1 3 4]
>> [A B]
>> size(ans)
>> [A ; B]
The following table gives data for the distance travel along five truck routes and the
corresponding time required to traveled each route. Use the data to compute the
average speed required to drive each route. Find the route that has the highest
average speed.
1 2 3 4 5
Distance (miles) 560 440 490 530 370
Time (hrs) 10.3 8.2 9.1 10.1 7.5
Solution:
>>d = [560, 440, 490, 530, 370]
>>t = [10.3, 8.2, 9.1, 10.1, 7.5]
>>speed = d./t
speed =
54.3689 53.6585 53.8462 52.4752 49.3333
>>[highest_speed, route] = max(speed)
highest_speed = route =
54.3689 1