Documente Academic
Documente Profesional
Documente Cultură
ANALYSIS
CHAPTER THREE
Programming with
MATLAB
3.1 M-FILES
>>
, Vs. ;
clc, Clear
i, j … (√-1)
predefined variables
(pi)
format compact
&
format loose
2.2.2 Arrays, Vectors, and Matrices
An array is a collection of values that are
represented by a single variable name.
One- dimensional arrays are called
vectors and two-dimensional arrays are
called
matrices.
Use Brackets [ ] to enter
arrays
Row Vectors
Column Vectors
1. Using ; 2. Using Enter
b = [2;4;6;8;10] b = [2
4
6
8
10]
3.Transposing Row Vectors
‘
>> b = [2 4 6 8 10]'
Matices
A=
1 2 3
4 5 6
7 8 9
1.
>> A = [1 2 3; 4 5 6; 7 8 9]
2.
>> A = [1 2 3
456
7 8 9]
3.
>> A = [[1 4 7]' [2 5 8]' [3 6 9]']
Calling individual elements of an array
ones
&
zeros
2.2.3 The Colon Operator
>> t = 1:5
>> t = 1:0.5:3
>> t = 10:−2:5
Using : to call elements
from vectors and matreces
2.2.4 The linspace and logspace Functions
linspace
linspace(x1, x2, n)
𝑋2 −𝑋1
Interval =
𝑛−1
logspace
logspace(x1, x2, n)
generates n logarithmically equally spaced
points between decades 10x1 and 10x2.
𝑋2 −𝑋1
Power Interval =
𝑛−1
2.2.5 Character Strings
>> f = 'Miles ';
>> s = 'Davis';
>> x = [f s]
ellipsis …
>> a = [1 2 3 4 5 ...
6 7 8]
https://www.mathsisfun.com/algebra/matrix-multiplying.html
>> A^2
>> A.^2
>> E = [−1.6 −1.5 −1.4 1.4 1.5 1.6];
>> round(E)
ans =
−2 −2 −1 1 2 2
>> ceil(E)
ans =
−1 −1 −1 2 2 2
>> floor(E)
ans =
−2 −2 −2 1 1 1
>> F = [3 5 4 6 1];
>> v = sqrt(g*m/cd)*tanh(sqrt(g*cd/m)*t)
2.5 GRAPHICS
>> plot(t, v)
>> plot(t, v)
>> title('Plot of v versus t')
>> xlabel('Values of t')
>> ylabel('Values of v')
>> grid
PROBLEMS
2.1
What is the output when the following commands
are implemented?
A = [1:3;2:2:6;3:−1:1]
A = A'
A(:,3) = []
A = [A(:,1) [4 5 7]' A(:,2)]
A = sum(diag(A))
Ex.1.1
الموعد النهائي
األسئلة المطلوبة رقم الشابتر
للتسليم
الخميس
07/03/2019 7,9 and 17 1
11:00 pm
السبت
09/03/2019 1,2,4,7,9,13,18,22 and 26 2
11:00 pm
األحد
10/03/2019 1,5,6,8,10,12,14 and 22 3
11:00 pm
جدول مناقشات األسبوع القادم