210 likes | 255 Views
ENG004 ALGORITHMS & INT. TO PROGRAMMING. Week 3 “ An introduction to arrays and matrices ” Ahmet Anıl Dindar 07.03.2007. The class facts. E-mail address : iku.eng004.01@gmail.com Class web page: http://web.iku.edu.tr/courses/insaat/eng004/. Last week.
E N D
ENG004 ALGORITHMS & INT. TO PROGRAMMING Week 3 “An introduction to arrays and matrices” Ahmet Anıl Dindar 07.03.2007
The class facts • E-mail address: iku.eng004.01@gmail.com • Class web page: http://web.iku.edu.tr/courses/insaat/eng004/ ENG004.01
Last week • What is Algorithm and Programming? • Why do we need programs? • A powerful tool- MATLAB • What is MATLAB? • Why MATLAB? • How to use it? The first commands in MATLAB. ENG004.01
This week • Variables • Defining a new variable • Assigning a value to a variable • Variable types • An introduction to arrays and matrices • Entering arrays and matrices • Creating arrays and matrices manually by entering values. • Generating arrays and matrices by defining certain rules • Creating arrays from existing arrays • By using built-in matrix generators ENG004.01
Variables • What is variable? Homer Simpson Are there anyone whose name is Homer Simpson? (probably) YES ENG004.01
Variables: • Variable is a tag given to a specific matrice, number or anything. • You can change the content of the variable any time. • You can name a variable with alphabetic or alpha-numeric. • The variables are important in programming. • A good sense and logic is essential to follow the codes. ENG004.01
And now let’s see How it is in MATLAB! Follow me now! ENG004.01
Variables in MATLAB (Alphabetic): >> a=1 a = 1 >> a=1 a = 1 >> a+a ans = 2 >> a=1 a = 1 >> a+a ans = 2 >> a*a ans = 1 ENG004.01
Variables in MATLAB (Alphanumeric): >> a1=10 a1 = 10 >> a1=10 a1 = 10 >> a1 a1 = 10 >> a1=10 a1 = 10 >> a1 a1 = 10 >> a1*(2*a1)/5 ans = 40 ENG004.01
Variables in MATLAB: >> a=10 a = 10 >> a1=5 a1 = 5 >> a+a1 ans = 15 >> a+a1*(a-a1) ans = 35 >> ENG004.01
An introduction to arrays and matrices • What is matrice? • What is array? • What are the matrices we use? • What are the calculations? • The properties of the matrices? • The matrices named with variables? ENG004.01
Creating a Matrice Row Matrix (Vector) >> a=[1 3 4] a = 1 3 4 Column Matrix (Vector) >> a1 = 1 2 3 ENG004.01
Creating a Matrice An Ordinary Matrice >> ali=[1 2 3;4 5 6;7 8 9] ali = 1 2 3 4 5 6 7 8 9 ENG004.01
Generating arrays and matrices by defining certain rules: Generic Creation (one by one): >> a=(1:10) a = Columns 1 through 7 1 2 3 4 5 6 7 Columns 8 through 10 8 9 10 Generic Creation (two by two): >> deli=(1:2:10) deli = 1 3 5 7 9 >> Generic Creation (???): >> deli=(10:-2:0) deli = 10 8 6 4 2 0 ENG004.01
Generating arrays and matrices by defining certain rules: Some Special Matrices >> ones(1,10) ans = 1 1 1 1 1 1 1 1 1 1 >> zeros(1,5) ans = 0 0 0 0 0 What about a matrice with full of 2’s >> twos(1,5) ENG004.01
Generating arrays and matrices by defining certain rules: Some Special Matrices >> ones(1,10) ans = 1 1 1 1 1 1 1 1 1 1 >> zeros(1,5) ans = 0 0 0 0 0 What about a matrice with full of 2’s >> twos(1,5) ENG004.01
Creating matrices from matrices Using matrices to create new matrices >> a=(1:5) a = 1 2 3 4 5 >> b=(2:6) b = 2 3 4 5 6 >> c=[a;b] c = 1 2 3 4 5 2 3 4 5 6 ENG004.01
Assignment • There is not any assignment! ENG004.01
Next week... ENG004.01
See you next week! ENG004.01