Preview

MATLAB Exercise: Artificial Intelligence

Good Essays
Open Document
Open Document
332 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
MATLAB Exercise: Artificial Intelligence
MATLAB EXERCISES
UEMH3163 / UECS2053 ARTIFICIAL INTELLIGENCE

1. Run the MATLAB code: a = 1:5; d = a+i*a; e = d' f = d.' g = mod(5,4)
2. Given A = [1 2 4; 1 1 1; 2 3 1] and B = [2 2 2; 2 2 2; 2 2 2]. Run the MATLAB code: a=A>B b=A>1
3. Given A = magic(4). Run MATLAB code :
DiagElement = diag(A)
DiagMatrix = diag(diag(A))
SuperDiagElement = diag(A,2)
4. Run the MATLAB code: name = upper('matlab') fun = strrep('hahaha','a','i') greet = 'Welcome'; where = 'to Joan''s'; party = 'birthday party';
¯nal = str2mat(greet, where, party) text = 'Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday';
[day,rest] = strtok(text,',')
[day2,rest] = strtok(rest,',')
5. Given A = [1 1; 2 2; 3 3; 4 100]. Run the MATLAB code : average = mean(A) med = median(A) dev = std(A)
6. Given A = [0 4 4; 2 0 2; 4 2 0]. Run the MATLAB code :
[Ascend,Ind] =sort(A)
Descend = flipud(sort(A))
7. Let be given the string 'Need-to-split-this-string'. We want to break it into the 5 strings 'Need', 'to',
'split', 'this', and 'string'.
8. Given A = [1 2 5 5 6 2 1 2]. Write a code that removes all 2's in matrix A.
9. Given A = [2 8 3 30 4 50 100 200 4 80 500]. Split it into three arrays with different ranges: (0-10),
(10-100), and (100-1000). The above array should become a = [2 8 3 4 4] b = [30 50 80] c = [100; 200; 500]

10. Given A = [1 2 3;4 5 6;7 8 10] and B = [1 2 5;3 5 -6]. Run MATLAB code :
A+B
A*A
A^2
B*A
A*B
A’
A.^2
[1,2,3].*[4,7,4]
[15 14 17]./[3 2 17]
[1 2 3]./[4 5]
11. Write a code to generate following outputs d = [-5 -4 -3 -2 -1 0 1 2 3 4 5] d = [1 4 7 10]
12. Given u = [1 0 2 4 0 2] and v = [5 6 1 0 0 7]. Run the following codes : u&v u|v
~u
u == 2 xor(u,v) any(v) all(v) find(u == 2)
13. Given A = magic(4). Run MATLAB codes :
A>13
x = find(A>13)
A(x) = 999
14. Write a loop that adds up random numbers, but makes sure that the sum of random numbers x stays below 20.0.
15. Write a for loop that adds up the numbers from 1 to

You May Also Find These Documents Helpful