Lab2 - Task1 - Sultan Momar Alshalabi - 422039543
Lab2 - Task1 - Sultan Momar Alshalabi - 422039543
Lab2 - Task1 - Sultan Momar Alshalabi - 422039543
Faculty of Engineering
Department of Electrical
كلية الهندسة
Engineering قسم الهندسة الكهربائية
ENGR 3032
LAB 2
Submitted To
Dr. Abdulmajeed Alenezi
Submitted By
Sultan Momar Alshalabi
422039543
Q1. Create a matrix named m of evenly spaced values from 0 to 10, with an increment of
1/10.
Answer: m=0:1/10:10
Result:
Q2. Use the linspace function to create a matrix of six evenly spaced values from 10 to 20.
Answer: A=linspace(10,20,6)
Q3. Use the logspace function to create a matrix of five logarithmically spaced values
between 10 and 100.
Answer: B=logspace(10,100,5)
Result:
B = 1.0000e+10 3.1623e+32 1.0000e+55 3.1623e+77 1.0000e+100
Task 2
x = [-2, -1, 0, 1, 2]
Answer: X=(-2:1:2)
Result: X = -2 -1 0 1 2
Result: Y = 2 1 0 1 2
QQ= sqrt(3)
QQ = 1.7321
W= nthroot(-3,2)
error: nthroot: N must be an odd integer if X contains negative values
H= nthroot(3,2)
H = 1.7321
C=-3^(1/2)
C = -1.7321
D= 3^(1/2)
D = 1.7321
J = -1 0 -1 0 1 0 1 0
Q4.There are 52 different cards in a deck. How many different hands of 5 cards each are
possible? Remember, every hand can be arranged 120 (5!) different ways.
Answer: P= nchoosek(52,5)
Result: P = 2598960
Q5.Very large prime numbers are used in cryptography. How many prime numbers are
there between 10,000 and 20,000? (These aren’t big enough primes to be useful in
ciphers.) (Hint: Use the primes function and the length command.)
Answer:
U= primes(20000);
Y=primes(10000);
G=length(U)-length(Y) %length of primes numbers between U and Y
Answer:
%Task 3
thetah=3*pi/2;
V= sin(2*thetah)
kk=[0:0.2*pi:2*pi];
Q2= cos(kk)
Q3= asin(1)
RT= [-1:0.2:1];
RR= acos(RT)
Result:
V = 3.6738e-16
Q2 = 1.0000 0.8090 0.3090 -0.3090 -0.8090 -1.0000 -0.8090 -0.3090 0.3090 0.8090
1.0000
Q3 = 1.5708
RR = 3.1416 2.4981 2.2143 1.9823 1.7722 1.5708 1.3694 1.1593 0.9273 0.6435
0
Result:
EV =
0.956925 0.450455 0.335663
0.079911 0.539150 0.157638
0.823759 0.897506 0.783992
ND =
-0.3863 -1.6478 0.8768
0.4245 -2.1568 1.8802
2.3864 -0.2946 -0.8054
Write an m-file to find the absolute value and the angle of each of the following vectors
(complex numbers). The m-file should be well formatted with sufficient comments (and
explanations) in the header. Attach the print-out of the screen shot of your m-file with output
results.
a. A = 1 + i
b. B = 2 + 3i
c. C = 8 + 2i
Answer:
%Task 5
AS = 1 + i;
BS = 2 + 3i;
CS = 8 + 2i;
AA= abs(AS)
NA= angle(AS)
AB= abs(BS)
NB= angle(BS)
AC= abs(CS)
NC= angle(CS)
Result:
AA = 1.4142
NA = 0.7854
AB = 3.6056
NB = 0.9828
AC = 8.2462
NC = 0.2450