Upload
el1temkdd
View
38
Download
3
Embed Size (px)
DESCRIPTION
Laboratoriski Vezbi Matlab, fsafsafsavcfsg, fsafdmfkdk
Citation preview
2013-2014
1 1
2013-2014
2 1
MATLAB . MATrix LABoratory. :
; import export ; ; ;
MATLAB;
MATLAB . , , , ...
MATLAB :
help
help topic
help command
help help help
helpwin o help
1.1. MATLAB
2013-2014
3 1
lookfor keyword , keyword
F1 .
()! :
;
, _;
MATLAB .. one OnE ;
MATLAB 31 ;
, MATLAB . ; .
, . .
:
ans : default
( answer);
pi : = 3.1415926;
eps : = 2.2204e-016,
;
Inf inf : , ;
NaN nan : ;
i : ;
:
who: ;
whos: ,
;
1.2.
2013-2014
4 1
clear: , ans
;
clear name: name;
clc: ;
clf: ;
:
abs (x) - | log10 (x) - 10 sin (x) - | rem (x,y) - cos (x) - | round (x) - tan (x) - | sqrt (x) - exp (x) - x | imag (x) - log (x) - | real (x) - , :
2+4+6. Enter.
2 + 4 + 6
ans =
12
MATLAB . : (4*25) + (6*22) - (2*99) :
4*25+6*22-2*99
ans = 34
A,B C MATLAB:
A=2
A =
2
B=4;
C=6
2013-2014
5 1
C =
6
D=A+B+C
D =
12
E=B*25+C*22-A*99
E =
34
A,B C 2,4 6 . , MATLAB . , , . :
C
C =
6
, who.
who Your variables are: A B C
:
1.1
/ \ 56/8 = 8\56
^ 5^2
2013-2014
6 1
! MATLAB . MATLAB 1x1 . , , - N:1 - 1:N.
: 24 52 65 1 ... 27 68
:
1
2
3
4
n-1
n
. ( ), . : 0.1. , (-). :
x= [0 0.1*pi 0.2*pi 0.3*pi 0.4*pi 0.5*pi 0.6*pi 0.7*pi 0.8*pi 0.9*pi pi]
x =
Columns 1 through 7
0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850
Columns 8 through 11
2.1991 2.5133 2.8274 3.1416
, ( ).
, :
y=sin(x)
y =
Columns 1 through 7
0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511
2013-2014
7 1
Columns 8 through 11
0.8090 0.5878 0.3090 0.0000
2-D plot(x,y), x y .
11 . , . MATLAB 1, 0. , :
x(3) % x
ans
0.6283
y(5) % y
ans =
0.9511
% . .
1 5:
x(1:5)
ans =
0 0.3142 0.6283 0.9425 1.2566
1.3. , x y
2013-2014
8 1
, . , , ( 1 , 2 ), .
x(2:2:7)
ans =
0.3142 0.9425 1.5708
, .
y(3:-1:1)
ans =
0.5878 0.3090 0
x(1:5) :
x(5:-1:1)
ans =
1.2566 0.9425 0.6283 0.3142 0
- MATLAB , - (;).
c = [1 ; 2 ; 3 ; 4 ; 5]
c =
1
2
3
4
5
2013-2014
9 1
' - - , . -, -. 1:2 1 2 1.
a = 1:5
a =
1 2 3 4 5
b =a'
b =
1
2
3
4
5
:
1.2.
x = start:end
- x start,
1 end
x = start:increment:end
- x start,
increment
end end
linspace(start,end,number) - x start,
end, number
length(x) x
y=x' x
2013-2014
10 1
1.2 ( .* ):
A = 2:6
A =
2 3 4 5 6
A + 5
ans =
7 8 9 10 11
B = -1:1:3
B =
-1 0 1 2 3
A .* B
ans =
-2 0 4 10 18
5 ( 2) ( 2).
linspace(A(1),B(5),length(A))
ans =
2.0000 2.2500 2.5000 2.7500 3.0000
:
A = [2, 5, 7, 1, 3];
B = [0, 6, 5, 3, 2];
A >= 5
ans =
0 1 1 0 0
A >= B
ans =
2013-2014
11 1
1 0 1 0 1
:
A = [2, 5, 7, 1, 3, 4];
odds = 1 : 2 : length(A)
odds =
1 3 5
A(odds)
ans =
2 7 3
! MATLAB . , MATLAB . MATLAB :
A=[1 2 3; 4 5 6; 7 8 9]
A =
1 2 3
4 5 6
7 8 9
. a
A(3,3)=0
A =
1 2 3
4 5 6
7 8 0
0 . ,
2013-2014
12 1
( ) .
A(2,6)=1
A =
1 2 3 0 0 0
4 5 6 0 0 1
7 8 0 0 0 0
, B.
A=[1 2 3;4 5 6; 7 8 9] ;
A =
1 2 3
4 5 6
7 8 9
B=A(3:-1:1, 1:3)
B =
7 8 9
4 5 6
1 2 3
, .
( ) :
ones(n) - nxn
ones(m,n) - mxn
zeros(n) - nxn
zeros(m,n) - mxn
rand(n) - nxn 0
1
2013-2014
13 1
rand(m,n) - mxn 0
1
size(A) - mxn , [m,n]
length(A) -
.
.
z = zeros(2,3)
z =
0 0 0
0 0 0
rand(2,3)
ans =
0.9501 0.6068 0.8913
0.2311 0.4860 0.7621
>> SpoenaMatrica = [z, ans, ones(2,4)]
SpoenaMatrica =
0 0 0 0.9501 0.6068 0.8913 1.0000 1.0000 1.0000 1.0000
0 0 0 0.2311 0.4860 0.7621 1.0000 1.0000 1.0000 1.0000
,
, :
, N:M M:K
. ,
.. .
,
MATLAB.
2013-2014
14 1
1.3
MATLAB
a + b a + b
a - b a - b
( ) a x b a .* b
a x b a * b
( ) a b a ./ b
a b a / b
ab a .^ b
: 1.3.
A B .
A = ones(2,3) * pi
A =
3.1416 3.1416 3.1416
3.1416 3.1416 3.1416
B = rand(2,3)
B =
0.3922 0.1712 0.0318
0.6555 0.7060 0.2769
C = A + B - ones(2,3)
C =
2.5338 2.3128 2.1734
2.7971 2.8476 2.4185
2013-2014
15 1
.
A .* C
ans =
7.9602 7.2658 6.8280
8.7873 8.9461 7.5980
, NxM MxK .
A * C
??? Error using ==> mtimes
Inner matrix dimensions must agree.
C(3,1) = 2
C =
2.5338 2.3128 2.1734
2.7971 2.8476 2.4185
2.0000 0 0
A * C
ans =
23.0307 16.2119 14.4260
23.0307 16.2119 14.4260
, .
A .* C
??? Error using ==> times
Matrix dimensions must agree.
. , 1.3. ,
2013-2014
16 1
.
MATLAB
. ,
:
{
:
[
] [
] [
]
:
1.)
: MATLAB :
A = [3, 2, -1; -1, 3, 2; 1, -1, -1];
b = [10; 5; -1];
x = inv(A) * b
x =
-2.0000
5.0000
-6.000
inv(A) MATLAB
, nxn.
2013-2014
17 1
2.)
: MATLAB :
A = [3, 2, -1; -1, 3, 2; 1, -1, -1];
b = [10; 5; -1];
x = \b % b/A
x =
-2.0000
5.0000
-6.000
.
inv(A) - , nxn
:
eye(n) - nxn
eye(n,m) - nxm
rank(A) -
det(A) -
* ,
*
* .
2013-2014
18 1
1.1. MATLAB: N , 0 2, N . y 2xN y , x . x . : N
N = 11;
N x- 0 2
x = linspace(0, 2*pi, N)
x =
0 0.6283 1.2566 1.8850 2.5133 3.1416 3.7699 4.3982 5.0265 5.6549 6.2832
y
y = cos(x)
y =
1.0000 0.8090 0.3090 -0.3090 -0.8090 -1.0000 -0.8090 -0.3090 0.3090 0.8090 1.0000
2xN y , x
= [y; x]
A =
1.0000 0.8090 0.3090 -0.3090 -0.8090 -1.0000 -0.8090 -0.3090 0.3090 0.8090 1.0000
0 0.6283 1.2566 1.8850 2.5133 3.1416 3.7699 4.3982 5.0265 5.6549 6.2832
2013-2014
19 1
x
= (1:2, N:-1:1)
A =
1.0000 0.8090 0.3090 -0.3090 -0.8090 -1.0000 -0.8090 -0.3090 0.3090 0.8090 1.0000
6.2832 5.6549 5.0265 4.3982 3.7699 3.1416 2.5133 1.8850 1.2566 0.6283 0
. x x, y y. , :
plot(x,y)
1.4. , 0 2, 11
2013-2014
20 1
1.2. MATLAB: ,
:
a)
{
b)
{
c)
{
d)
{