You are on page 1of 3



Final Test Practice


Description This is a practice test for the Final Test

Comments Questions about this test will be answered in Room : NH.Communal Centre
131.Lecture Rm (145, NH.AP30.L02.131) from 11am to 1pm.

Date Due Monday 26th of May 2014

Assessment % This test is not assessed


1 Demonstrate and apply Matlab programming knowledge and problem solving skill to solve basic
engineering problems and process experimental data.
2 Demonstrate the ability to employ student centred learning, creativity, problem solving, critical
thinking, decision-making and communication skills to effectively complete individual and team

1 JEE101 MAY 19TH 2014

Exercise 1 (10%):
A vector is given by x = [3.3 5.1 7 1 2.99 8 13 1.6 2 1.1 4 4]. Create two vectors from x: One call I
which contains the elements of x that are integers and one call F that contains the elements of x that are
not integers. In both I and F, the elements should be in the same order than in x.

Exercise 2 (15%):
The following Mathematical function is considered:

( )

(a) Plot the function y(x) for (5%)

(b) Find the three x positions where y = 0 and plot them on the previous figure. (5%)
(c) Find the local maximum within the interval and the local minimum within the
interval . Plot the results on the previous figure. (5%)

Exercise 3 (15%):
(a) Write a user-define function that fits data points to a power function of the form .
Name the function [ ] ( ), where the input arguments x and y are vectors
with the coordinates of the data points and the output arguments b and m are the constants of
the fitted exponential equation. (5%)
(b) Use powerfit to fit the data below: (5%)

x 0.4 2.5 3.3 5.0 6.2 8.0

y 0.7 19.3 38.2 88.2 155 224

(c) Make a plot that shows the data points and the function. (5%)

Exercise 4 (40%):
If we assume negligible air friction and ignore the curvature of the Earth, a ball that is thrown into the
air from any point on the Earths surface will follow a parabolic flight path. The height of the ball at
any time t after it is thrown is given by:

( )

where is the initial height of the ball above the ground, is the initial vertical velocity of the ball,
and g is the acceleration due to Earths gravity. The horizontal distance (range) travelled by the ball as
a function of time after it is thrown is given by:

( )

where is the initial horizontal position of the ball on the ground and is the initial horizontal
velocity of the ball.
If the ball is thrown with some initial velocity at an angle of degrees with respect to the Earths
surface, then the initial horizontal and vertical components of the velocity will be:

2 JEE101 MAY 19TH 2014

(a) First consider that the initial position is ( , ) = (0,0), the initial velocity is = 20m/s and
the angle . From the expression of the height, calculate the time for the ball to
reach the ground ( ( ) = 0) and the total horizontal distance travel by the ball ( ( )). Plot
the trajectory of the ball for . (5%)
(b) Repeat the previous question but for an initial position of ( , ) = (0,1.5m). (5%)
(c) Write a user defined function Range which calculates the total horizontal distance travelled by
the ball given the velocity , the angle and the initial height . Consider = 0. (10%)
(d) Using the function Range, find the angle which returns the maximum horizontal distance
the ball can travel using and = 20m/s. (10%)
(e) On a same figure plot the trajectory of the ball for different values of = 10, 20, and 90
and using a bold line the trajectory for = . (10%)

Exercise 5 (20%):
Function dir returns the contents of a specified directory. The dir command returns a structure array
with four fields, as shown here:

>> d=dir(C:\Users\jrpnader\Documents\MATLAB)

4x1 struct array with fields:

The field name contains the names of each file, date contains the last modification date for the file,
bytes contains the size of the file in bytes, isdir is zero for conventional files and 1 for directories and
datenum contains the Matlab serial date number related to date.

(a) Write a user-defined function that accepts a path (Ex: C:\Users\jrpnader\Documents\) and
directory name (Ex: MATLAB) returns the total size of all files in the directory in bytes.
SizeF=SizeFiles(Path, directory_name). (10%)
(b) Recursion. A function is said recursive if the function calls itself. Create a new function
SizeF=TotSizeFiles(Path, directory_name) which is similar to SizeFiles but calls itself when it
finds a subdirectory and sums up the size of all files in the current directory plus all
subdirectories. (10%)
(Warning: the two first output of dir are a directory call . which is related to the current
directory and a directory call .. which is related to the parent directory. Even if the related
isdir field is 1 for these directories, TotSizeFiles should not look for files within this directory.)

3 JEE101 MAY 19TH 2014