You are on page 1of 3

# KNJ2332 Engineering Programming

## Semester 2 Session 2014/2015

Department of Mechanical and Manufacturing Engineering
Assignment 1

Instructions:
1. Assignment to be done INDIVIDUAL only.
2. Follow the sample printed guideline for the correct format.
3. Submit hard copy only with the following instruction:
a) Written answer Question 1, and
b) Printed answer (Print screen, then paste and crop both script (if required) and
output in Command Window) Question 2.
4. Command input in Command Window must always starts with name, matrics number,
group and clock for Question 2.
5. Dateline of submission: 5th May 2015, Monday, 5:00pm.
______________________________________________________________________________
Guideline:

## QUESTION 1 (10 marks)

a) Give the MATLAB syntax for these mathematical calculations:

i)

(3x) 3
5e 3
2

[1 marks]

ii)

35 43
53 145

[1 marks]

iii)

8 log10 (7) + ln 8

[1 marks]

iv)

8 cos 1 (7)

[1 marks]

v)

5e ( 2.1) 33

[1 marks]

b) Predict the MATLAB output of writing the below code in Command Window:

i)

x = 1 * 3 * 7

[1 marks]

ii)

## x = sqrt([144, 100, 121])

[1 marks]

iii)

x = linspace(5, 20, 7)

[1 marks]

iv)

x = [(3:6) 3 7 3]

[1 marks]

v)

eye(4)

[1 marks]

## a) Using the script files:

The volume of a cylinder is r2h. Give a script with input command where user can
input radius, r and height, h to find volume. Generate a sample output command. If r
= 3 cm and h = 7 cm, solve the volume of the cylinder?
(5 marks)
b) Type this matrix in Matlab Command Window and use Matlab to answer the following
questions:
X=
3
7
3
7
8
6 -2
5 12
7
6
9
0 -2 -6
11 18
6
6
4
a.

b.

c.

## Distinguish 4 x 2 array a consisting of all elements in the second through three

columns of X.
(3 marks)
Distinguish 2 x 5 array b consisting of all elements in the third through fourth
rows of X.
(3 marks)
Distinguish 2 x 3 array c consisting of all elements in the second through third
rows and second through fourth columns of X.
(3 marks)

c) The surface area of a sphere is 4r2. Solve the surface area of a sphere with a radius of 20
cm.
(3 marks)
d) Use MATLAB to evaluate

at = 5.

8 3 9 2 7
10 3 + 5 2 3 7
(3 marks)