Professional Documents
Culture Documents
1
> 10/2\5-3+2*4
ans =
> 3^2/4
ans =
2.2500
> 2+round(6/9+3*2)/2-3
ans =
2.5000
> 2+floor(6/11)/2-3
ans =
-1
> 2+ceil(-6/9)/2-3
ans =
-1
> fix(-4/9)+fix(3*(5/6))
ans =
--------------------------
1.2
> mod(36,15)
ans =
> rem(30,15)
ans =
0
> gcd(30,15)
ans =
15
> lcm(30,15)
ans =
30
----------------------
1.3
> 1&-1
ans =
> 13&(-6)
ans =
> 0<=0.2<0.4
ans =
> 5>4>3
ans =
> 2>3&1
ans =
0
-------------------------
1.4
> x=[3 1 5 7 9 6]
x =
3 1 5 7 9 6
> x=[3 1 5 7 9 2 6]
x =
3 1 5 7 9 2 6
> x(3)
ans =
> x(1:7)
ans =
3 1 5 7 9 2 6
> x(6:-2:1)
ans =
2 7 1
> x([1 6 2 1 1 ])
ans =
3 2 1 3 3
> sum(x),min(x),max(x)
ans =
33
ans =
ans =
>
--------------------
1.5
> x=[1 5 2 8 9 0 1]
x =
1 5 2 8 9 0 1
> y =[5 2 2 6 0 0 2]
y =
5 2 2 6 0 0 2
> x>y
ans =
0 1 0 1 1 0 0
> y<x
ans =
0 1 0 1 1 0 0
> x==y
ans =
0 0 1 0 0 1 0
> x<=y
ans =
1 0 1 0 0 1 1
> y>=x
ans =
1 0 1 0 0 1 1
> x|y
ans =
1 1 1 1 1 0 1
> x&y
ans =
1 1 1 1 0 0 1
> x&(-y)
ans =
1 1 1 1 0 0 1
> (x>y)|(y<x)
ans =
0 1 0 1 1 0 0
> (x>y)&(y<x)
ans =
0 1 0 1 1 0 0
------------------
1.6
> a=[1 0 2]
a =
1 0 2
> b=[0 2 2]
b =
0 2 2
> a=b
a =
0 2 2
> a<b
ans =
0 1 0
> a<b<a
ans =
1 0 1
> a<b<b
ans =
0 1 1
> a|(a)
ans =
1 0 1
> b&(b)
ans =
0 1 1
> a=b==a
a =
0 0 1
------------------------
1.7
> x =1:10
x =
1 2 3 4 5 6 7 8 9 10
> y = [3 1 5 6 8 2 9 4 7 0]
y =
3 1 5 6 8 2 9 4 7 0
> x>3
ans =
0 0 0 1 1 1 1 1 1 1
> x<8
ans =
1 1 1 1 1 1 1 0 0 0
> (x>3)&(x<8)
ans =
0 0 0 1 1 1 1 0 0 0
> x(x>5)
ans =
6 7 8 9 10
> y(x<=4)
ans =
3 1 5 6
> x((x<2)|(x>=8))
ans =
1 8 9 10
> y((x<2)|(x>=8))
ans =
3 4 7 0
> x(y<0)
ans =
x =
2 -5 1 6
> x=x+16
x =
18 11 17 22
> x =[2 -5 1 6]
x =
2 -5 1 6
> x([1:2:end])=x([1:2:end])+3
x =
5 -5 4 6
-------------------------
1.10
> x= randperm(35)
x =
Columns 1 through 10
32 22 34 35 6 3 16 11 30 33
Columns 11 through 20
7 28 17 14 8 5 29 21 25 31
Columns 21 through 30
27 26 19 15 1 23 2 4 18 24
Columns 31 through 35
13 9 20 10 12
> y= ones(1,35)
y =
Columns 1 through 10
1 1 1 1 1 1 1 1 1 1
Columns 11 through 20
1 1 1 1 1 1 1 1 1 1
Columns 21 through 30
1 1 1 1 1 1 1 1 1 1
Columns 31 through 35
1 1 1 1 1
> y(x<6)=2
y =
Columns 1 through 10
1 1 1 1 1 2 1 1 1 1
Columns 11 through 20
1 1 1 1 1 2 1 1 1 1
Columns 21 through 30
1 1 1 1 2 1 2 2 1 1
Columns 31 through 35
1 1 1 1 1
> y((x>=6)&(x<=20))=x((6<=x)&(x<=20))-4
y =
Columns 1 through 10
1 1 1 1 2 2 12 7 1 1
Columns 11 through 20
3 1 13 10 4 2 1 1 1 1
Columns 21 through 30
1 1 15 11 2 1 2 2 14 1
Columns 31 through 35
9 5 16 6 8
y =
Columns 1 through 10
1 14 1 1 2 2 12 7 1 1
Columns 11 through 20
3 1 13 10 4 2 1 15 11 1
Columns 21 through 30
1 1 15 11 2 13 2 2 14 12
Columns 31 through 35
9 5 16 6 8
------------------------------
1.11
> x = [3 15 9 12 -1 0 -12 9 6 1]
x =
3 15 9 12 -1 0 -12 9 6 1
> x(x>0)=0
s
x =
0 0 0 0 -1 0 -12 0 0 0
> x = [3 15 9 12 -1 0 -12 9 6 1]
x =
3 15 9 12 -1 0 -12 9 6 1
> x(mod(x,3)==0)=3
x =
3 3 3 3 -1 3 3 3 3 1
1.8
> x=[1 4 8]
x =
1 4 8
> y=[2 1 5]
y =
2 1 5
A =
2 7 9 7
3 1 5 6
8 1 2 5
> [x;y']
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
> [x;y]
ans =
1 4 8
2 1 5
ans =
2 7
3 6
8 5
ans =
5 3
2 8
> A(:)
ans =
2
3
8
7
1
1
9
5
2
7
6
5
> [A;A(end,:)]
ans =
2 7 9 7
3 1 5 6
8 1 2 5
8 1 2 5
> A(1:3,:)
ans =
2 7 9 7
3 1 5 6
8 1 2 5
> [A;A(1:2,:)]
ans =
2 7 9 7
3 1 5 6
8 1 2 5
2 7 9 7
3 1 5 6
1.11
> clear
> x=[3 15 9 12 -1 0 -12 9 6 1]
x =
3 15 9 12 -1 0 -12 9 6 1
> mod(7,3)
ans =
> size(x)
ans =
1 10
> a=x
a =
3 15 9 12 -1 0 -12 9 6 1
> a(a>0)=0
a =
0 0 0 0 -1 0 -12 0 0 0
> b=x
b =
3 15 9 12 -1 0 -12 9 6 1
> b=b(mod(b,3)=0)
b=b(mod(b,3)=0)
↑
Error: The expression to the left of the equals sign is not a
valid target for an assignment.
> b=b(mod(b,3)==0)
b =
3 15 9 12 0 -12 9 6
> b=x
b =
3 15 9 12 -1 0 -12 9 6 1
> b(mod(b,3)==0)=3
b =
3 3 3 3 -1 3 3 3 3 1
> c=x
c =
3 15 9 12 -1 0 -12 9 6 1
> c(mod(c,2)=0)=c(mod(c,2)=0)*5
c(mod(c,2)=0)=c(mod(c,2)=0)*5
↑
Error: The expression to the left of the equals sign is not a
valid target for an assignment.
> c(mod(c,2)==0)=c(mod(c,2)==0)*5
c =
3 15 9 60 -1 0 -60 9 30 1
> y=x(x>10)
y =
15 12
> d=x
d =
3 15 9 12 -1 0 -12 9 6 1
> d(d<aver(d))=0
> d(d<ave(d))=0
> d(d<mean(d))=0
d =
0 15 9 12 0 0 0 9 6 0
> sum(x)
ans =
42
>
1.12
> x=[3 2 6 8 ]'
x =
3
2
6
8
y =
4
1
3
5
> y=x+y
y =
7
3
9
13
y =
4
1
3
5
> y=sum(x)+y
y =
23
20
22
24
> x.^y
ans =
1.0e+21 *
0.0000
0.0000
0.0001
4.7224
> y./x
ans =
7.6667
10.0000
3.6667
3.0000
> z=x.*y
z =
69
40
132
192
> w=sum(z)
w =
433
> x.*y-w
ans =
-364
-393
-301
-241
> sum(x.*y)
ans =
433
>
1.13
> clear
> x=[1 4 8]
x =
1 4 8
> y=[2 1 5]
y =
2 1 5
A =
3 1 6
5 2 7
> x+y
ans =
3 5 13
> x+A
Error using +
Matrix dimensions must agree.
> x'+y
Error using +
Matrix dimensions must agree.
A =
1 2
4 1
8 5
> A-3
ans =
-2 -1
1 -2
5 2
1.14
> clear
> A=[2 7 9 7 ;3 1 5 6 ;8 1 2 5 ]
A =
2 7 9 7
3 1 5 6
8 1 2 5
> A'
ans =
2 3 8
7 1 1
9 5 2
7 6 5
> sum(A)
ans =
13 9 16 18
> sum(A')
ans =
25 15 16
> sum(A,2)
ans =
25
15
16
> sum(A,1)
ans =
13 9 16 18
> sum(A,3)
ans =
2 7 9 7
3 1 5 6
8 1 2 5
ans =
2 7 9 7 25
3 1 5 6 15
8 1 2 5 16
13 9 16 18 56
>
1.15
> A=randi([-10,10],4)
A =
7 -4 1 6
2 5 -9 9
1 5 -9 -8
9 -3 1 1
> D=A
D =
7 -4 1 6
2 5 -9 9
1 5 -9 -8
9 -3 1 1
> D(D~=0)=1./D(D~=0)
D =
> D=1./D(D~=0)
D =
7
2
1
9
-4
5
5
-3
1
-9
-9
1
6
9
-8
1
> B=A
B =
7 -4 1 6
2 5 -9 9
1 5 -9 -8
9 -3 1 1
> B=B([1,2];:)+10
B=B([1,2];:)+10
↑
Error: Unbalanced or unexpected parenthesis or bracket.
> B=B([1,2],:)+10
B =
17 6 11 16
12 15 1 19
> B=A
B =
7 -4 1 6
2 5 -9 9
1 5 -9 -8
9 -3 1 1
> B([1,2],:)=B([1,2],:)+10
B =
17 6 11 16
12 15 1 19
1 5 -9 -8
9 -3 1 1
> C=A
C =
7 -4 1 6
2 5 -9 9
1 5 -9 -8
9 -3 1 1
> C(:,[1,4])=C(:,[1,4])+10
C =
17 -4 1 16
12 5 -9 19
11 5 -9 2
19 -3 1 11
> E=A
E =
7 -4 1 6
2 5 -9 9
1 5 -9 -8
9 -3 1 1
> E(E>0)=E(E>0).^(1/2)
E =
>
1.16
> clear
> A=[2 4 1;6 7 2;3 5 9]
A =
2 4 1
6 7 2
3 5 9
> x=A(1,:)
x =
2 4 1
> y=A([2,3],:)
y =
6 7 2
3 5 9
> max(A)
ans =
6 7 9
> max(max(A))
ans =
> min(min(A))
ans =
> min(A(:))
ans =
> max(A(:))
ans =
9
> sum(A(:))
ans =
39
>
1.17
> clear
> A=[2 1 0;-2 5 -1;3 4 9]
A =
2 1 0
-2 5 -1
3 4 9
B =
3 1 2
-1 3 -2
3 4 5
> X=A*inv(b)
X =
> X=B*inv(A)
X =
> A(2,:)=()
A(2,:)=()
↑
Error: Unbalanced or unexpected parenthesis or bracket.
> A(:,0)=()
A(:,0)=()
↑
Error: Unbalanced or unexpected parenthesis or bracket.
> A(:,2)=[]
A =
2 0
-2 -1
3 9
A =
2 0 3
-2 -1 -1
3 9 3
A =
2 1 0
-2 5 -1
3 4 9
A =
2 1 0 3
-2 5 -1 -1
3 4 9 3
>
1.18
> x=-pi:0.1:pi;
> y=x+sin(x);
> plot(x,y)
> xlabel('x')
> ylabel('y')
> hold on
> y=(x.^2).*sin(x);
> plot(x,y)
> legend('y=x+sin(x)','(x^2)*sin(x)')
> title('đồ thị hàm số')
>
1.19
> clear
> syms x
> g = exp(x)
g =
exp(x)
> ezplot(g)
> ezplot(g,[-2,2])
>
1.20
> x=linspace(0,2*pi);
> y=sin(x);
> plot(x,y)
> hold on
> y=sin(x+pi/2);
> plot(x,y)
> y=sin(x+pi/3);
> plot(x,y)
1.21
> syms x y
> ezmesh(sin(x)*cos(y),[0 10 0 10])
>
> ezmesh(x^2-y^2,[-2,2,-2,2])
>
> ezmesh(sin(x^5)*cos(y))
>
1.22
> [X,Y]=meshgrid(-1:.2:1);
> Z=X.^2-Y.^2;
> contour(Z)
> contour(X, Y, Z)
> contourf(X, Y, Z)
> contour(X, Y, Z,10)
> contour(X, Y, Z,20)
> contourf(X, Y, Z,20)
>