matlab代写-DEC 13 2017

Computational Methods ASSESSMENT DEC 13 2017
Dr. Catherine O’Sullivan
1. This is a coursework assessment however no collaboration between
students is allowed.
and cannot be used. Removable storage (e.g. usb keys) may not be
used. The network is being monitored and students violating these
conditions will be identified and disciplined. HOWEVER YOU
CAN ACCESS THE MATLAB HELP FACILITIES
3. All roughwork should be completed on the final two sheets of this
handout.
4. These guidelines with your name on them should be submitted at the
end of the assessment.
work continuously to the h: drive to avoid any loss of files.
6. Your name and student id number should be included in all MATLAB
files as a comment.
7. The assessment contains two compulsory questions. Each question is
worth 25 marks.
I have read and understand these instructions:
• Name (Print clearly):
• Signature:
1
Problem 1
Part A Develop a function called avestd.m that takes as input a one
dimensional array and returns both artithmetic mean and the standard de-
viation of the numbers stored in the array.
1. The mean or average of a series xi of N numbers is given by
x¯ =
1
N
N∑
i=1
xi (1)
2. The formula for the standard deviation for a series xi of N numbers is
given by
σ =
√∑N
i=1 (xi − x¯)2
N − 1 (2)
[15 marks]
Part B You should find a datafile called“examresults.dat” on your S-
drive. This file contains the examination results for a set of 100 students.
Develop a script file called prob1.m that
1. Reads the data in “examresults.dat” and loads them in to memory.
2. Creates a figure with a histogram with 20 bins that gives a visual
overview of the examination data.
3. Uses the function avestd.m to calculate the average mark and the
standard deviation of the marks.
[10 marks]
2
Problem 2
Part A
Develop a MATLAB function called funcp2 that takes as input two
numbers (scalars) x and y and returns value of z which is calculated as
follows:
• If −pi < x < pi and −pi < y < pi z = cos(x) ∗ cos(y)
• z=0 for any other combination of x and y.
[9 marks]
Part B
Develop a script file called Problem2.m that achieves the following:
• Efficiently generates two one-dimensional arrays a and b each storing
values ranging from -4 to 4 in increments of 0.1.
• Uses an appropriate for loop and the function funcp2 to create a 2-
dimensional array storing values of c based upon a systematic, sequen-
tial combination of the values stored in arrays a and b.
• Creates a contour plot of the values of c using a and b to define the
horizontal coordinates.
• Creates a surface plot of the values of c using a and b to define the
horizontal coordinates.
[16 marks]
3
ROUGHWORK PAGE 1
4
ROUGHWORK PAGE 2
5 