ENG004 ALGORITHMS & INT. TO PROGRAMMING Week 3 “An introduction to arrays and matrices” Ahmet Anıl Dindar
ENG The class facts address: Class web page:
ENG 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.
ENG 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 Generating arrays and matrices by defining certain rules Creating arrays from existing arrays By using built-in matrix generators
ENG Variables What is variable? Homer Simpson Are there anyone whose name is Homer Simpson? (probably) YES
ENG 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.
ENG And now let’s see How it is in MATLAB! Follow me now!
ENG >> a=1 a = 1 >> a=1 a = 1 >> a+a ans = 2 Variables in MATLAB (Alphabetic): >> a=1 a = 1 >> a+a ans = 2 >> a*a ans = 1
ENG >> a1=10 a1 = 10 >> a1=10 a1 = 10 >> a1 a1 = 10 Variables in MATLAB (Alphanumeric): >> a1=10 a1 = 10 >> a1 a1 = 10 >> a1*(2*a1)/5 ans = 40
ENG >> a=10 a = 10 >> a1=5 a1 = 5 >> a+a1 ans = 15 >> a+a1*(a-a1) ans = 35 >> Variables in MATLAB:
ENG 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?
ENG Creating a Matrice >> a=[1 3 4] a = >> a1 = Row Matrix (Vector) Column Matrix (Vector)
ENG Creating a Matrice >> ali=[1 2 3;4 5 6;7 8 9] ali = An Ordinary Matrice
ENG Generating arrays and matrices by defining certain rules: >> a=(1:10) a = Columns 1 through Columns 8 through Generic Creation (one by one): >> deli=(1:2:10) deli = >> Generic Creation (two by two): >> deli=(10:-2:0) deli = Generic Creation (???):
ENG Generating arrays and matrices by defining certain rules: >> ones(1,10) ans = >> zeros(1,5) ans = Some Special Matrices What about a matrice with full of 2’s >> twos(1,5)
ENG Generating arrays and matrices by defining certain rules: >> ones(1,10) ans = >> zeros(1,5) ans = Some Special Matrices What about a matrice with full of 2’s >> twos(1,5)
ENG Creating matrices from matrices >> a=(1:5) a = >> b=(2:6) b = >> c=[a;b] c = Using matrices to create new matrices
ENG Assignment There is not any assignment!
ENG Next week... WeeksDateClassAssignment Introduction to the classRegistration Exploring MATLABAssignment Arrays and Matrix Operations N.A Arrays and Matrix Operations Assignment Arrays and Matrix OperationsAssignment Polynomials and curve-fitting Assignment Descriptive statistics Assignment Programming Elements of MATLAB N.A Programming Elements of MATLAB Assignment Programming Elements of MATLAB Assignment Plotting and Animations N.A Plotting and Animations Assignment Numerical Integration Assignment Symbolic Math Assignment Take-home final projectN.A.
ENG See you next week!
ENG