首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导FEEG6002C1程序、C/C++编程调试、讲解c++程序 讲解R语言编程|辅导留学生 Statistics统计、回归、迭代
项目预算:
开发周期:
发布时间:
要求地区:
UNIVERSITY OF SOUTHAMPTON FEEG6002C1
______________________________________________________
SEMESTER 1 ASSESSMENT PAPER 2020/21
Advanced Computational Methods 1
DURATION – 24 hours
______________________________________________________
This paper contains five questions. Answer all questions.
This is an online assessment. The solution document must be
submitted via Blackboard only. Please submit your answers to
all questions using a single word document.
Please use Quincy (free download from below link)
http://www.codecutter.net/tools/quincy/
or use any of the following freely available on-line C compilers
to write, compile and execute C programmes.
https://www.onlinegdb.com/online_c_compiler
https://www.programiz.com/c-programming/online-compiler/
A total of 100 marks are available for this paper.
2 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 2 of 15
Question 1:
a). Why do you want to work on a remote system (or remote server)?
(3 marks)
b). What is a terminal?
(2 marks)
c). Why do you need a terminal in the Linux operating system?
(2 marks)
d). What is the motivation of using shell scripts in the Linux operating system?
(3 marks)
e). List three different Linux shell types?
(3 marks)
f). What is the motivation of using make files in the Linux operating system?
(3 marks)
g). Explain with steps how to create make files in the Linux operating system?
(4 marks)
h). What is a function in C programming?
(2 marks)
i). C programming offers two types of functions. What are they, and how are they
different?
(2 marks)
j). Show two methods for defining a symbolic constant named MAXIMUM that has a
value of 200.
(2 marks)
k). If a function does not return a value, what type should be used to declare it?
(2 marks)
l). In a one-dimensional array declared with n elements, what is the subscript of the
last element?
(2 marks)
(30 marks)
3 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 3 of 15
Question 2:
Fill in the blanks in each of the following.
a). The first element of an array has index ______.
b). The ______ operator returns the number of bytes used to store a variable type t.
c). To declare a pointer of type char, you need to use _______.
d). Memory allocation through _______ takes place at run time.
e). C programs consist only of _______.
f). ______ need to be given before the function can be called.
g). If you use constants in a C-program, it is good practice to define a _____.
h). ________ is a special macro representing End Of File.
i). ________ is a valuable function for allowing user input to a C program.
j). With the ______, C program can use alias names of data types that are machine
specific.
(10 Marks)
4 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 4 of 15
Question 3:
In this question you will develop a set of functions to manipulate 3x3 matrices in
various ways.
a) Write a function print_matrix(…) which takes as an input a two-dimensional
array of size nxn of type double representing a matrix, and an integer n
corresponding to the size of this array. The function should print the elements of this
array to the standard output displaying it in the form of a matrix. For example, we
expect:
1 0
0 1
for a 2x2 array a with elements a[0][0]=1, a[0][1]=0, a[1][0]=0,
a[1][1]=1. The function print_matrix(…) does not return any value.
(2 marks)
b) Write a function transpose(…) which takes as an input a 3x3 array a of type
double representing a matrix, and returns a transpose of this matrix stored in the
same input variable a. Note the transpose of a square matrix 𝑎𝑖𝑗 is defined as:
(𝑎)𝑖𝑗
𝑇 = 𝑎𝑗𝑖.
(2 marks)
c) Write a function det2(…) which takes as an input a 2x2 array a of type
double representing a matrix, and returns a variable of type double equal to the
determinant of the input matrix:
|𝑎| = |
𝑎00 𝑎01
𝑎10 𝑎11
| = 𝑎00𝑎11 − 𝑎01𝑎10.
(2 marks)
d) Write a function cofactor(…) which takes as an input a 3x3 array a of type
double representing a matrix, and two integers i and j, and returns a variable of
type double equal to the cofactor 𝑐𝑖𝑗 of the matrix a. The cofactor 𝑐𝑖𝑗 is defined as:
5 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 5 of 15
where 𝑚𝑖𝑗 is the minor of the element 𝑎𝑖𝑗 of the 3x3 matrix a, equal to the
determinant of the reduced 2x2 matrix obtained by removing all elements of the ith
row and jth column of the matrix a. Thus the notation 𝑎𝑘𝑙
(𝑖𝑗)
in the above equation
means the elements of the matrix remaining after removing the ith row and jth
column from the matrix a. Use function det2(…) developed above to simplify your
code.
(4 marks)
e) Write a function det3(…) which takes as an input a 3x3 array a of type
double representing a matrix, and returns a variable of type double equal to the
determinant of the input matrix a. To evaluate the determinant |𝑎| of a matrix 𝑎 use
the Laplace expansion method:
|𝑎| = ∑𝑎𝑘𝑖𝑐𝑘𝑖
2
𝑘=0
𝑖 = 0 𝑜𝑟 1 𝑜𝑟 2
where 𝑐𝑘𝑖 is the cofactor of the matrix 𝑎 as defined above. Note that the index i is
fixed and the result is independent of the choice of i. Use the function
cofactor(…) developed as part of the previous question to simplify your code.
(4 marks)
f) Write a function inverse(…) which takes as an input a 3x3 array a of type
double representing a matrix, and returns an inverse of this matrix stored in the
same input variable a. To calculate the inverse matrix 𝑎
−1 of a matrix 𝑎, note that the
elements of the inverse matrix can be expressed as:
where 𝑐𝑖𝑗 denotes the cofactor of the matrix a and |𝑎| is the determinant of the matrix
a. Use your functions det3(…) and cofactor(…) developed above to simplify
your code.
(4 marks)
g) Write a function multiply(…) which takes as an input two 3x3 arrays of type
double representing two matrices. The function should calculate the matrix product
of the two matrices and print it to the standard output using the function
print_matrix(…) developed above. The function multiply(…) does not
return any value.
(2 marks)
6 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 6 of 15
Example of incomplete function main() could look like this:
int main(void)
{
…
…
printf("\nOriginal matrix:\n");
print_matrix(3, a);
printf("Determinant of the matrix:\n");
printf("%f\n", det3(a));
printf("\nTranspose of the matrix:\n");
transpose(a);
print_matrix(3, a);
printf("Inverse of the matrix:\n");
transpose(a); // transpose back to obtain original
matrix
for(i=0; i
for(j=0; j
ainv[i][j] = a[i][j]; // copy of a to invert
inverse(ainv);
print_matrix(3, ainv);
printf("Check that the product gives unit
matrix.\n");
multiply(a, ainv);
…
}
and assuming the given choice of the matrix the expected output if the missing parts
have been populated is:
Original matrix:
1.000000 0.000000 1.000000
0.000000 1.000000 1.000000
0.000000 0.000000 1.000000
Determinant of the matrix:
7 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 7 of 15
1.000000
Transpose of the matrix:
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
1.000000 1.000000 1.000000
Inverse of the matrix:
1.000000 -0.000000 -1.000000
-0.000000 1.000000 -1.000000
0.000000 -0.000000 1.000000
Check that the product gives unit matrix.
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
(20 marks)
8 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 8 of 15
Question 4:
In this question you will evaluate the statistics of the United States presidential
election in 2012. You are given a file uselecton2012.txt which has 5 tabdelimited
columns:
Alabama 795696 0 1255925 9
Alaska 122640 0 164676 3
Arizona 1025232 0 1233654 11
Arkansas 394409 0 647744 6
…
…
The 1st column represents the state name, 2nd and 3rd columns the democratic popular
and electoral votes, and 4rd and 5th columns represent the republican popular and
electoral votes. Reference:
https://en.wikipedia.org/wiki/2012_United_States_presidential_election.
a) Write a function count_lines(…) which takes as input a file name string and
returns an integer equal to the count of the number of lines in the input file with the
given name.
(2 marks)
b) Write a structure votes which has the following members:
char state[100]; // state name
long dempv; // democrats popular votes
long demev; // democrats electoral votes
long reppv; // republicans popular votes
long repev; // republicans electoral votes
(2 marks)
c) In function main(…) call the function count_lines(…) to determine the
number of lines nlines in the file uselection2012.txt. Allocate dynamically
the array arr to be nlines long with elements being of type structure votes.
(2 marks)
d) Write a function initialise_votes(…) which takes as input a file name
string, a pointer to an array of structures of type votes, and an integer
corresponding to the length of this array. The function will be called in main(…) for
example as:
initialise_votes("uselection2012.txt", arr, nlines);
9 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 9 of 15
and populate the members of each structure given in the array arr by information
contained in each corresponding line in uselection2012.txt. Thus, after
calling the function initialise_votes(…) the members of the structure
arr[0] should be:
state=‘Alabama’; dempv=795696; demev=0; reppv=1255925;
repev=9;
the members of the structure arr[1] should be:
state=‘Alaska’; dempv=122640; demev=0; reppv=164676;
repev=3;
and so on. The function initialise_votes(…) does not return any value, and
the output should be available through the input pointer arr.
(4 marks)
e) Write a function print_list(…) which takes as an input a pointer to an array
of structures of type votes and an integer corresponding to the length of this array.
The function will be called in main(…) for example as:
print_list(arr, nlines);
The function does not return any value and will only print the content of the file to
the standard output. You can use this function to check if your initialisation of the
array of structures arr correctly reflects the format of the file
uselecton2012.txt, i.e.:
Alabama 795696 0 1255925 9
Alaska 122640 0 164676 3
Arizona 1025232 0 1233654 11
…
(2 marks)
f) Write a function print_vote_state(…) which takes as an input a pointer to
an array of structures of type votes and an integer corresponding to the length of
this array. The function will be called in main(…) for example as:
maxstate = print_vote_state(arr, nlines);
10 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 10 of 15
where the output variable maxstate is a structure of type votes, and corresponds
to the state with the highest counts of the popular votes determined from among both
democrat and republican electoral votes.
(4 marks)
g) Write a function print_vote_total(…) which takes as an input a pointer to
an array of structures of type votes and an integer corresponding to the length of
this array. The function will be called in main(…) for example as:
print_vote_total(arr, nlines);
and will print to standard output four numbers corresponding to the total sum of
popular and electoral votes for democrats, and for republicans. The function
print_vote_total(…) should return a string “dem. win” or “rep. win”
depending on the higher value of the total values of electoral votes.
(4 marks)
An example of incomplete function main(…) could look like this:
int main(void){
…
nlines = count_lines("uselection2012.txt");
…
…
initialise_votes("uselection2012.txt", arr, nlines);
print_list(arr, nlines);
printf("\n");
maxstate = print_vote_state(arr, nlines);
printf("%s wins with %ld (dem) and %ld (rep) popular
votes.\n", maxstate.state, maxstate.dempv,
maxstate.reppv);
printf("\n");
printf("%s\n", print_vote_total(arr, nlines));
11 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 11 of 15
…
…
}
and the expected output if the missing parts have been populated correctly is:
Alabama 795696 0 1255925 9
Alaska 122640 0 164676 3
Arizona 1025232 0 1233654 11
Arkansas 394409 0 647744 6
California 7854285 55 4839958 0
…
…
…
WestVirginia 238269 0 417655 5
Wisconsin 1620985 10 1407966 0
Wyoming 69286 0 170962 3
California wins with 7854285 (dem) and 4839958 (rep)
popular votes.
Dem. pop. vote total: 65915794
Dem. el. vote total: 332
Rep. pop. vote total: 60933504
Rep. el. vote total: 206
Dem. wins
(20 marks)
12 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 12 of 15
Question 5:
This question will consider solving the predator-and-prey population dynamics
problem. The problem can be mathematically stated as follows. Let 𝑝1(𝑡) be the
number (population) of rabbits and 𝑝2(𝑡) the number of foxes. The time-dependence
of 𝑝1 and 𝑝2
is governed by the following conditions:
- Rabbits proliferate at a rate 𝑎, and per unit time a number 𝑎𝑝1
is born.
- Number of rabbits is reduced by collisions with foxes. Per unit time 𝑐𝑝1𝑝2
rabbits are eaten.
- Birth rate of foxes depends only on food intake in form of rabbits.
- Foxes die a natural death at a rate 𝑏.
This dynamics can be expressed by the following system of first order differential
equations (ODE):
𝑑𝑝1
𝑑𝑡 = 𝑎𝑝1 − 𝑐𝑝1𝑝2 = 𝑓1(𝑝1
, 𝑝2)
𝑑𝑝2
𝑑𝑡 = 𝑐𝑝1𝑝2 − 𝑏𝑝2 = 𝑓2(𝑝1
, 𝑝2)
The task is to solve this system of equations. To obtain the solution, assume:
- Rabbit birth rate 𝑎 = 0.7
- Rabbit-fox collision rate 𝑐 = 0.007
- Fox death rate 𝑏 = 1
- Initial conditions 𝑝1
(0) = 70 and 𝑝2
(0) = 50
- Time interval from 0 to 30 (dimensionless)
a) Write a function fode2(…) which returns type void and takes as input two
arrays of type double. Each of the arrays has two elements. The first array stores the
variables 𝑝1
, 𝑝2
. The second array stores the values of the right hand sides 𝑓1 and 𝑓2
,
and serves as the output of the function fode2(…).
(5 marks)
b) Extend the function euler(…) given in lecture 8 as:
void euler(double *t, double *y, double y0,
double (*f)(double, double), int n)
{
int i;
float dt = t[1] - t[0]; // step
13 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 13 of 15
y[0] = y0; // initial condition
for (i = 0; i < n; i++)
{
y[i + 1] = y[i] + dt * f(t[i], y[i]);
}
}
to incorporate the arrays for populations of both rabbits and foxes, including the
function fode2(…) developed above.
(10 marks)
c) In main(…) run the function euler(…) with appropriate inputs, and export the
data for time 𝑡 and populations 𝑝1 and 𝑝2
to the file data.txt. Use your favourite
software to plot the data (see figure 1 below).
(5 marks)
An example of incomplete function main(…) could look like this:
#include
#include
#include
#define Ti 0.0 // initial time
#define Tf 30.0 // final time
#define dT 0.001 // time step
#define Y01 70.0 // initial condition 1
#define Y02 50.0 // initial condition 2
#define A 0.7
#define C 0.007
#define B 1
…
…
int main()
{
…
…
for(i=0; i<=N; i++)
14 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 14 of 15
{
t[i] = Ti + dT*i; // define time
}
euler(y1, y2, fode2, N); // y1, y2 to store
solutions
// no explicit time
dependence
// print to file
for(i=0; i<=N; i++)
{
fprintf(fw, "%f\t%f\t%f\n", t[i], y1[i], y2[i]);
}
…
…
}
and when the missing parts have been populated the expected output is as shown in
Figure 1 below. You can use this figure to compare with your solution.
15 FEEG6002C1
Copyright 2021 v01 © University of Southampton Page 15 of 15
Figure 1 – Example of the plot calculated using the extended Euler algorithm
assuming parameters listed in the figure title. Populates of rabbits and foxes reach a
steady state with a phase lag.
(20 marks)
END OF PAPER
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!