Hina 001 - Compressed
Hina 001 - Compressed
12
3. X=x+2 x=
14
4. Y=x+3 y=
17
5. Y*6 ans =
102
6. X*y-x*3-y ans =
179
7. X=y^2 x=
289
8. Z=sqrt(y) z=
4.1231
9. X=2;y=4; z=x+y z=
6
10. Z=x*y z=
8
11. X=12e6 x=
12000000
12. Clc
13. X=rand x=
0.8147
14. X=rand x=
0.9058
15. Help rand rand Uniformly distributed pseudorandom numbers.
R = rand(N) returns an N-by-N matrix containing
pseudorandom values drawn
from the standard uniform distribution on the open
interval(0,1). rand(M,N)
or rand([M,N]) returns an M-by-N matrix.
rand(M,N,P,...) or
rand([M,N,P,...]) returns an M-by-N-by-P-by-...
array. rand returns a
scalar. rand(SIZE(A)) returns an array the same
size as A.
Examples:
-2.3562
12) Who ans x y z
13) Whos Name Size Bytes Class Attributes
2 8 18 32 50
5. Z=x*y Error using *
Incorrect dimensions for matrix multiplication.
Check that the number of columns in the first
matrix matches the number of rows in the second
matrix. To perform elementwise multiplication,
use '.*'.
Related documentation
6. Z=x./y z=
2 2 2 2 2
7. Z=x/y z=
2.0000
8. 2*y ans =
2 4 6 8 10
9. Z=0:10 z=
0 1 2 3 4 5 6 7 8 9 10
10. Sum(z) ans =
55
11. Y=[2 1 4 -3] Y=
2 1 4 -3
12. Y=[2;1;4;-3] Y=
2
1
4
-3
13. Z=y’ z=
1
2
3
4
5
14. Z(1) ans =
1
15 Z(2) ans =
2
16. Z(1:3) ans =
1
2
3
17. Z(2:4) ans =
2
3
4
18. Length(z) ans =
5
19. X=[2 4 8 16] x=
2 4 8 16
20. Y=log2(x) y=
1 2 3 4
21. Y^2 Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a
power. Check that the matrix is square and the
power is a scalar. To perform elementwise matrix
powers, use '.^'.
22. y.^2 ans =
1 4 9 16
23. Y=rand(1,5) y=
0.8147 0.9058 0.1270 0.9134 0.6324
24. Y=rand(4) y=
0.0975 0.9649 0.4854 0.9157
0.2785 0.1576 0.8003 0.7922
0.5469 0.9706 0.1419 0.9595
0.9575 0.9572 0.4218 0.6557
25. Y=[7 3 -1 2] y=
7 3 -1 2
26. Mean(y) ans =
2.7500
27. Var(y) ans =
10.9167
28. Min(y) ans =
-1
29. Max(y) ans =
7
30. [a b]= min(y) a=
-1
b=
3
31. Sort(y) ans =
-1 2 3 7
32. Y=[y 5] y=
7 3 -1 2 5
33. Z=[y(3:4) x(1:2)] z=
-1 2 2 4
1. D Operation of Matrices
QNo. Input Output
1. X=[3 6 -2 -1; 0 5 2 1;7 -1 4
8]
2. X(2, 1) ans =
0
3. X(2,3) ans =
2
4. X(1, :) ans =
3 6 -2 -1
5. X(:,2) ans =
6
5
-1
6. X(1:2,:) ans =
3 6 -2 -1
0 5 2 1
7. X(:,2:3) ans =
6 -2
5 2
-1 4
8. Y=[1 0 2;3 2 1;2 3 4] y=
1 0 2
3 2 1
2 3 4
9. Y’ ans =
1 3 2
0 2 3
2 1 4
10. Z=zeros(3,4);
11. Y(1,:)=x(2,:) y=
0 5 2 1
0 0 0 0
0 0 0 0
12. Y(2,:)=x(1,:) y=
0 5 2 1
3 6 -2 -1
0 0 0 0
13. Y(3,:)=[1 2 3 4] y=
0 5 2 1
3 6 -2 -1
1 2 3 4
14. Z=x-y z=
3 1 -4 -2
-3 -1 4 2
6 -3 1 4
15. Z=x*y Error using *
Incorrect dimensions for matrix multiplication.
Check that the number of columns in the first
matrix matches the number of rows in the second
matrix. To perform elementwise multiplication,
use '.*'.
16. Z=x*y’ z=
25 50 5
30 25 20
11 -1 49
17. Z=x.*y z=
0 30 -4 -1
0 30 -4 -1
7 -2 12 32
18. Z=x^2 Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a
power. Check that the matrix is square and the
power is a scalar. To perform elementwise matrix
powers, use '.^'.
19. Z=x.^2 z=
9 36 4 1
0 25 4 1
49 1 16 64
20. Z=2.^x z=
8.0000 64.0000 0.2500 0.5000
1.0000 32.0000 4.0000 2.0000
128.0000 0.5000 16.0000 256.0000
21. Z=x.^2+3*y z=
9 51 10 4
9 43 -2 -2
52 7 25 76
22. Max(z) ans =
52 51 25 76
23. [T1 T2]=max(z) T1 =
52 51 25 76
T2 =
3 1 3 3
24. Mean(z) ans =
23.3333 33.6667 11.0000 26.0000
25. Max(mean(z)) ans =
33.6667
26. Max(max(z)) ans =
76
27. Z=rand(4) z=
0.8147 0.6324 0.9575 0.9572
0.9058 0.0975 0.9649 0.4854
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419
28. X=inv(z) x=
-15.2997 3.0761 14.7235 9.6445
-0.2088 -1.8442 1.0366 1.8711
14.5694 -1.9337 -14.6497 -9.0413
-0.3690 0.5345 1.4378 -0.4008
29. Y=x*z y=
1.0000 -0.0000 0 -0.0000
-0.0000 1.0000 0 0.0000
0 0.0000 1.0000 0.0000
0 -0.0000 -0.0000 1.0000
30. Size(z) ans =
4 4
Columns 73 through 81
Columns 82 through 90
Columns 91 through 99
-0.4575 -0.5440
3. Y2=cos(x);
4. Plot(x)
5. Plot(y1)
6. Plot(x,y1) %compare to
5
7. Grid
8. Hold on
9. plot(x,y2)
10. y3=exp(-x) y3 =
Columns 1 through 9
1.0000 0.9048 0.8187 0.7408 0.6703 0.6065
0.5488 0.4966 0.4493
Columns 10 through 18
0.4066 0.3679 0.3329 0.3012 0.2725 0.2466
0.2231 0.2019 0.1827
Columns 19 through 27
0.1653 0.1496 0.1353 0.1225 0.1108 0.1003
0.0907 0.0821 0.0743
Columns 28 through 36
0.0672 0.0608 0.0550 0.0498 0.0450 0.0408
0.0369 0.0334 0.0302
Columns 37 through 45
0.0273 0.0247 0.0224 0.0202 0.0183 0.0166
0.0150 0.0136 0.0123
Columns 46 through 54
0.0111 0.0101 0.0091 0.0082 0.0074 0.0067
0.0061 0.0055 0.0050
Columns 55 through 63
0.0045 0.0041 0.0037 0.0033 0.0030 0.0027
0.0025 0.0022 0.0020
Columns 64 through 72
0.0018 0.0017 0.0015 0.0014 0.0012 0.0011
0.0010 0.0009 0.0008
Columns 73 through 81
17. plot(x,y1)
18. subplot(3,1,2)
19. plot(x,y2)
20. subplot(3,1,3)
21. plot(x,y3)
Example
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
24. help semilogy semilogy Semi-log scale plot.
semilogy(...) is the same as PLOT(...), except a
logarithmic (base 10) scale is used for the Y-axis.
1.F Boolean operations and plotting graphs over a limited range of the x
axis
QNO. Input Output
1. A=[0 1 2 3 4];
2. A<3 ans =
1×5 logical array
1 1 1 0 0
3. B=(A>2) B=
1×5 logical array
0 0 0 1 1
4. C=([1 1 0 0] & [ C=
1 1 1 0]) 1×4 logical array
1 1 0 0
5. C=([1 1 0 0] | [ 1 C =1×4 logical array
1 1 0]) 1 1 1 0
6. C=∼[1 0 1 0 0] C=∼[1 0 1 0 0]
↑
Error: Invalid text character. Check for unsupported symbol,
invisible character, or pasting of
non-ASCII characters.
7. C=([1 0 1 1 C=
1]==[1 0 1 0 0]) 1×5 logical array
1 1 1 0 0
8. C=([1 0 1 1] C=([1 0 1 1] ∼=[1 0 1 0 0])
∼=[1 0 1 0 0]) ↑
Error: Invalid text character. Check for unsupported symbol,
invisible character, or pasting of
non-ASCII characters.
9. x=0:0.01:10;
10. y=(x<3);
11. figure figure
↑
Error: Invalid text character. Check for unsupported symbol,
invisible character, or pasting of
non-ASCII characters.
12. plot(x,y);axis([0
10 -2 2]);grid;
13. y=(1<x)&(x<4);
14. plot(x,y);axis([0
10 -2 2]);grid;
15. y=1<x<4;
16. plot(x,y);axis([0 plot(x,y);axis([0 10 –2 2]);grid;
10 –2 2]);grid; ↑
Error: Invalid text character. Check for unsupported symbol,
invisible character, or pasting of
non-ASCII characters.
2.A Write down what each of the lines in the following box does and capture
the execution result.
Q No Input Output
1 syms a b c x t No output
2 y=sin(t); No output
3 diff(y) ans =
cos(t)
4 int(y) ans =
-cos(t)
5 int(y, t, 0, pi) ans =
2
6 z=int(xˆ2*exp(- z=int(xˆ2*exp(-x),x,1,3)
x),x,1,3) ↑
Error: Invalid text character. Check for unsupported
symbol, invisible character, or pasting of
non-ASCII characters.
7 double(z) ans =
1
9 symsum(xˆ2, x,1,4) symsum(xˆ2, x,1,4)
↑
Error: Invalid text character. Check for unsupported
symbol, invisible character, or pasting of
non-ASCII characters.
10 T=solve(a*xˆ2+b*x+ T=solve(a*xˆ2+b*x+c,x)
c,x) ↑
Error: Invalid text character. Check for unsupported
symbol, invisible character, or pasting of
non-ASCII characters.
11 T2=solve(a*xˆ2+b*x T2=solve(a*xˆ2+b*x+c,b)
+c,b) ↑
Error: Invalid text character. Check for unsupported
symbol, invisible character, or pasting of
non-ASCII characters.
12 a=1;b=2;c=3; No Output
13 z=eval(T) Unrecognized function or variable 'T'.
14 a=t; No output
z=eval(T) Unrecognized function or variable 'T'.
Q No Input Output
4.A function xdB=lin2dB(x) Ans= 20
xdB=10*log10(x);
4.B
fx=1/sqrt(2*pi*v)*exp(-(x-
m).^2/(2*v));
plot(x,fx)
4.C function e = swap(A,row0col1,c,d) function e = swap(A,row0col1,c,d)
e = A; ↑
if row0col1 == 0 Error: Function definition are not supported in this
context. Functions can only be created as local or
e(d,:) = A(c,:); nested functions in code files.
e(c,:) = A(d,:);
end
if row0col1 == 1
e(:,d)=A(:,c);
e(:,c)=A(:,d);
End
4.C2 >>x=rand(4,5) >>x=rand(4,5) >>y=swap(x,0,2,4) >>z=swap(y,1,5,1)
>>y=swap(x,0,2,4) ↑
>>z=swap(y,1,5,1) Invalid use of operator.
Simulink: -
Creating Subsystem
PART B : GUI