CE 205-MATLAB For Civil Engineers: Irfan Turk Fatih University, 2013-14
CE 205-MATLAB For Civil Engineers: Irfan Turk Fatih University, 2013-14
CE 205-MATLAB For Civil Engineers: Irfan Turk Fatih University, 2013-14
Irfan Turk
Fatih University, 2013-14
What is MATLAB?
MATLAB stands for MATrix LABoratory.
MATLAB is a high-performance language for technical
computing.
Math , computation, and numerical calculations
Algorithm development
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical user interface
building
Many toolboxes for different applications
MATLAB ENVIRONMENT
Command Window
Type commands
Current Directory
View folders and m-files
Workspace
View program variables
Command History
View past commands
Editor
Writing the code
Variables & Arrays
Variables :
int b;
No need for types, and pre-defining. double a;
float c;
Variable names must begin with a letter, followed by any
combination of letters, numbers and the underscore (_)
character Example:
>>1B=1;
>>_A1=-8;
All variables are created with double precision(as matrices)
unless specified.
Example:
>>x=1;
>>x1=-8;
Above, the variables are 1x1 matrices with double precision
Row 1
Row 2
Row 3
array(2,4)
Row 4
Row # Column #
Practice Exercise 2.1
Type the following expressions into MATLAB at the
command prompt, and observe the results:
5+2
5*2
3+2*(4+3)
2.54*8/2.6
6.3-2.1045
3.6^2
1+2^2
sqrt(5)
cos(pi)
Practice Exercise 2.2
Which of the following names are allowed in MATLAB? Make your
predictions, then test them with the isvarname, iskeyword, and which
commands.
1. test
2. Test
3. if
4. my-book
5. my_book
6. Thisisoneeverylongnamebutisitstillallowed?
7. 1stgroup
8. group_1
9. zzaAbc
10. 34wAwy?12#
11. sin
12. log
Operators
+ addition a+b
- subtraction a-b
* multiplication a*b
/ division a/b
^ power a^b
complex conjugate transpose a (apostrophe)
Examples:
Example 1: For a given A(3by3), and B(3by3) matrices,
find A+B, A-B, A*B, B*A,A, B, A^2, and B^2
Example 2:
2*x+3*y+4*z=-2,
4*x -y+ z= 3,
-3*x +3*y+ z=-4
Write the above system by using matrices and find
unkowns (x,y,z)
Operators(Element by element)
.* multiplication a .* b
./ division a ./ b
.^power a .^ b
x= y= b= c= d=
1 2 3 7 8 9 7 16 27 0.14 0.25 0.33 1 4 9
Examples
Example 5(in book, it is Example 2.1-2nd question):
Volume V=1000
Temperature T=300
Pressure P=100
Molecular weight MW=29
Gas Constant R=8.314
What is mass=m=? Solve it in Matlab
(PV=nRT, and n=m/MW)
Numeric Display Formats
Matlab Command Display Example
a) 0x 2*pi, 1+cos(x)
b) -2*pix pi, sin(x)-1
c) -4x 4, x^2-4