ENG004 ALGORITHMS & INT. TO PROGRAMMING
-
Upload
vance-pace -
Category
Documents
-
view
18 -
download
0
description
Transcript of ENG004 ALGORITHMS & INT. TO PROGRAMMING
![Page 1: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/1.jpg)
ENG004 ALGORITHMS & INT. TO PROGRAMMING
Week 3
“An introduction to arrays and matrices”
Ahmet Anıl Dindar
07.03.2007
![Page 2: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/2.jpg)
ENG004.01 2
The class facts
E-mail address: [email protected]
Class web page: http://web.iku.edu.tr/courses/insaat/eng004/
![Page 3: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/3.jpg)
ENG004.01 3
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.
![Page 4: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/4.jpg)
ENG004.01 4
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
![Page 5: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/5.jpg)
ENG004.01 5
Variables
What is variable?
Homer Simpson
Are there anyonewhose name is
Homer Simpson?(probably)
YES
![Page 6: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/6.jpg)
ENG004.01 6
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.
![Page 7: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/7.jpg)
ENG004.01 7
And now let’s see How it is in MATLAB!
Follow me now!
![Page 8: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/8.jpg)
ENG004.01 8
>> a=1a = 1 >> a=1
a = 1>> a+aans = 2
Variables in MATLAB (Alphabetic):
>> a=1a = 1>> a+aans = 2>> a*aans = 1
![Page 9: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/9.jpg)
ENG004.01 9
>> a1=10a1 = 10
>> a1=10a1 = 10>> a1a1 = 10
Variables in MATLAB (Alphanumeric):
>> a1=10a1 = 10>> a1a1 = 10>> a1*(2*a1)/5ans = 40
![Page 10: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/10.jpg)
ENG004.01 10
>> a=10a = 10>> a1=5a1 = 5>> a+a1ans = 15>> a+a1*(a-a1)ans = 35>>
Variables in MATLAB:
![Page 11: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/11.jpg)
ENG004.01 11
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?
![Page 12: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/12.jpg)
ENG004.01 12
Creating a Matrice
>> a=[1 3 4]a = 1 3 4
>> a1 = 1 2 3
Row Matrix (Vector)
Column Matrix (Vector)
![Page 13: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/13.jpg)
ENG004.01 13
Creating a Matrice
>> ali=[1 2 3;4 5 6;7 8 9]ali = 1 2 3 4 5 6 7 8 9
An Ordinary Matrice
![Page 14: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/14.jpg)
ENG004.01 14
Generating arrays and matrices by defining certain rules:
>> a=(1:10)a = Columns 1 through 7 1 2 3 4 5 6 7 Columns 8 through 10 8 9 10
Generic Creation (one by one):
>> deli=(1:2:10)deli = 1 3 5 7 9>>
Generic Creation (two by two):
>> deli=(10:-2:0)deli = 10 8 6 4 2 0
Generic Creation (???):
![Page 15: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/15.jpg)
ENG004.01 15
Generating arrays and matrices by defining certain rules:
>> ones(1,10)ans = 1 1 1 1 1 1 1 1 1 1>> zeros(1,5)ans = 0 0 0 0 0
Some Special Matrices
What about a matrice with full of 2’s>> twos(1,5)
![Page 16: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/16.jpg)
ENG004.01 16
Generating arrays and matrices by defining certain rules:
>> ones(1,10)ans = 1 1 1 1 1 1 1 1 1 1>> zeros(1,5)ans = 0 0 0 0 0
Some Special Matrices
What about a matrice with full of 2’s>> twos(1,5)
![Page 17: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/17.jpg)
ENG004.01 17
Creating matrices from 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
Using matrices to create new matrices
![Page 18: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/18.jpg)
ENG004.01 18
Assignment
There is not any assignment!
![Page 19: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/19.jpg)
ENG004.01 19
Next week...
Weeks Date Class Assignment
1 21.02 Introduction to the class Registration
2 28.02 Exploring MATLAB Assignment 1
3 07.03 Arrays and Matrix Operations N.A.
4 14.03 Arrays and Matrix Operations Assignment 2
5 21.03 Arrays and Matrix Operations Assignment 3
6 28.03 Polynomials and curve-fitting Assignment 4
7 04.04 Descriptive statistics Assignment 5
8 11.04 Programming Elements of MATLAB N.A.
9 18.04 Programming Elements of MATLAB Assignment 6
10 25.04 Programming Elements of MATLAB Assignment 7
11 02.05 Plotting and Animations N.A.
12 09.05 Plotting and Animations Assignment 8
13 16.05 Numerical Integration Assignment 9
14 23.05 Symbolic Math Assignment 10
15 30.05 Take-home final project N.A.
![Page 20: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/20.jpg)
ENG004.01 20
See you next week!
![Page 21: ENG004 ALGORITHMS & INT. TO PROGRAMMING](https://reader036.fdocuments.in/reader036/viewer/2022062408/56813652550346895d9dd8d1/html5/thumbnails/21.jpg)
ENG004.01 21