100% found this document useful (1 vote)
54 views2 pages

SOLUTION - PRACTICE - Introduction To MATLAB

This document provides MATLAB code examples for: 1) Basic operations on vectors such as addition, multiplication, exponentiation, and element-wise operations 2) Logical, trigonometric, exponential and other mathematical functions applied to vectors 3) Array indexing and operations including accessing rows and columns, summing, and reshaping arrays

Uploaded by

Covyn Yong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
54 views2 pages

SOLUTION - PRACTICE - Introduction To MATLAB

This document provides MATLAB code examples for: 1) Basic operations on vectors such as addition, multiplication, exponentiation, and element-wise operations 2) Logical, trigonometric, exponential and other mathematical functions applied to vectors 3) Array indexing and operations including accessing rows and columns, summing, and reshaping arrays

Uploaded by

Covyn Yong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Taylor’s University Computing Applications for Engineers

School of Engineering (ENG60104)

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)

4. Use MATLAB to check your answer

5. The function "rats" just displays the contents of a variable


a = 2:2:20
b = 10:-2:-4
c1 = 1:5, c2 = 1./c1 , rats(c2)

6. n = 1:100;
x = ( (-1).^(n+1) ) ./ (2*n - 1);
y = sum(x)

7. >> x=2; y=5;


(a) >> (y*x^3)/(x-y)
ans =
-13.3333
(b) >> (3*x)/(2*y)
ans =
0.6000
(c) >> (3/2)*(x*y)
ans =
15
(d) >> (4*(y-5))/(3*(x-6))
ans =
0

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

10. >> vnew=1.3*v


vnew =
8.1681e+003
>> rnew=sqrt(vnew/(pi*h))
rnew =
5.7009

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

You might also like