Академический Документы
Профессиональный Документы
Культура Документы
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.
Exercise 2 (15%):
The following Mathematical function is considered:
( )
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%)
(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:
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)
d=
4x1 struct array with fields:
name
date
bytes
isdir
datenum
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.)