Sunteți pe pagina 1din 4

Taylor’s University Computing Applications for Engineers

School of Engineering (ENG2314) Dr Thein Chung Ket

SOLUTION – PRACTICE 2

A) Relational/Logical exercises
Refer to Matlab

B) Control Flow-IF-block exercises

1. n = 7 gives m = 8
n = 9 gives m = -1
n = -10 gives m = -11

2. z = 1 gives w = 2
z = 9 gives w = 0
z = 60 gives w = sqrt(60)
z = 200 gives w = 200

3. T = 50 gives h = 0
T = 15 gives h = 31
T = 0 gives h = 1

4. x = -1 gives y = 500
x = 5 gives y = 20
x = 30 gives y = 120
x = 100 gives y = 500

In this last exercise, y = 4x for any input! Relational operations


are subject to precedence and ordering just as arithmetical
operations. The logical phrase a < x < b should be rendered as
the compound logical expression ((a < x) & (x < b)) in MATLAB.

5.

Page 1 of 4
Taylor’s University Computing Applications for Engineers
School of Engineering (ENG2314) Dr Thein Chung Ket

C) Loop constructs: for and while

D) Solve the following questions

Q1a)

r=
10000 20000 35200 100000 200000

>> v=[120 80 110 200 350]


v=
120 80 110 200 350

>> v./r
ans =
0.0120 0.0040 0.0031 0.0020 0.0018

Q1b)

>> p= v.*v
p=
14400 6400 12100 40000 122500

>> z=p./r
z=
1.4400 0.3200 0.3438 0.4000 0.6125

Page 2 of 4
Taylor’s University Computing Applications for Engineers
School of Engineering (ENG2314) Dr Thein Chung Ket

Q2)

>> distance = [550 430 480 530 370]


distance =
550 430 480 530 370

>> time = [10.3 8.2 9.1 10.1 7.5]


time =
10.3000 8.2000 9.1000 10.1000 7.5000

>> speed = distance./time


speed =
53.3981 52.4390 52.7473 52.4752 49.3333

Q3a)
> force = [400 550 700 500 600]
force =
400 550 700 500 600

>> distance = [2 0.5 0.75 1.5 3]


distance =

Page 3 of 4
Taylor’s University Computing Applications for Engineers
School of Engineering (ENG2314) Dr Thein Chung Ket

2.0000 0.5000 0.7500 1.5000 3.0000

>> W = force.*distance
W=
800 275 525 750 1800

Q3b)
>> z=sum(W)
z=
4150

Page 4 of 4

S-ar putea să vă placă și