SOLUTION - PRACTICE - Introduction To MATLAB
SOLUTION - PRACTICE - Introduction To MATLAB
1. x = 32:2:75
2. x = [2 5 1 6]
a = x + 16
b = x(1:2:end) + 3 Note: odd index element refer to 1st and 3rd element
c = sqrt(x) or c = x.^(0.5)
d = x.^2 or d = x.*x If the question ask for odd number, then the
answer will be x(2:1:end-1)+3
3. x = [3 2 6 8]', y = [4 1 3 5]'
a = y + sum(x)
b = x.^y
c = y./x
z = x.*y
w = sum(z)
x'*y - w (same thing)
6. n = 1:100;
x = ( (-1).^(n+1) ) ./ (2*n - 1);
y = sum(x)
Page 1 of 2
Taylor’s University Computing Applications for Engineers
School of Engineering (ENG60104)
8. t = 1:0.2:2
a = log(2 + t + t.^2)
b = exp(t).*(1 + cos(3*t))
c = cos(t).^2 + sin(t).^2 (all ones!)
d = atan(t)
e = cot(t)
f = sec(t).^2 + cot(t) - 1
9. h = 80
>> r=50/10
r=
5
>> v=pi*(r^2)*h
v=
6.2832e+003
B) Array exercises
1. A = [ 2 4 1 ; 6 7 2 ; 3 5 9]
x1 = A(1,:)
y = A(end-1:end,:)
c = sum(A)
d = sum(A,2) or d = sum(A')'
2. A = [2 7 9 7 ; 3 1 5 6 ; 8 1 2 5]
B = A(:,2:2:end)
C = A(1:2:end,:)
c = reshape(A,4,3) or c = A' (they are different but are both 4x3)
d = 1./A , rats(d)
e = sqrt(A)
Page 2 of 2