首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
MA117留学生编程讲解、c++,Java,Python程序设计辅导 辅导Web开发|辅导Python编程
项目预算:
开发周期:
发布时间:
要求地区:
MA117 Programming for Scientists: Project 2 Deadline: 12pm, Friday 19th March 2021
1
MA117 Project 2: Root Finding
Administrative Details
• This project is the second of the three assignments required for the assessment in this course. It is to
be submitted by 12pm, Friday 19th March 2021. Details of the method of the submission via the Tabula
system have been described in the lecture notes and are also available on the course web page.
• This assignment will count for 35% of your total grade in the course.
• The automated submission system requires that you closely follow instructions about the format of
certain files; failure to do so will result in the severe loss of points in this assessment.
• You may work on the assignment during the lab session, provided you have completed the other tasks
that have been set. You can use the work areas at all times when they are not booked for teaching, 7
days per week. If you are working on the assignment on your home system you are advised to make
regular back-up copies (for example by transferring the files to the University systems). You should
note that no allowance will be made for domestic disasters involving your own computer system. You
should make sure well ahead of the deadline that you are able to transfer all necessary files to the
University system and that it works there as well.
• The Tabula system will be open for the submission of this assignment starting from 1st March 2021.
You will not be able to test your code for correctness using Tabula but you can resubmit your work
several times, until the deadline, if you find a mistake after your submission. A later submission always
replaces the older one, but you have to re-submit all files.
• Remember that all work you submit should be your own work. Do not be tempted to copy work; this
assignment is not meant to be a team exercise. There are both human and automated techniques to
detect pieces of the code which have been copied from others. If you are stuck, then ask for assistance
in the lab sessions. TAs will not complete the exercise for you, but they will help if you do not
understand the problem, are confused by an error message, need advice on how to debug the code,
require further explanation of a feature of Java or similar matters.
• If you have more general or administrative problems e-mail me immediately. Always include the course
number (MA117) in the subject of your e-mail.
1 Formulation of the Problem
Finding the roots of a function is a classical and extremely well-known problem which is important in many
branches of mathematics. In Analysis II, you have probably seen that it is often easy to prove results about
the existence of roots. For example, using the Intermediate Value Theorem, you should easily be able to
prove that the function 𝑓(𝑥) = 𝑥 − cos 𝑥 has a root in the interval [0,1]. On the other hand, calculating an
exact value for this root is impossible, since the equation is transcendental.
MA117 Programming for Scientists: Project 2 Deadline: 12pm, Friday 19th March 2021
2
Root finding is a classic computational mathematical problem, and as such there are many algorithms which
one may use to approximate the roots of a function. In this project, you will write a program which uses the
Secant algorithm. Let 𝑓 ∶ ℂ → ℂ be continuously differentiable and pick two points 𝑧0, 𝑧1 ∈ ℂ. Consider the
sequence of complex numbers {𝑧𝑛
}𝑛=1
∞ generated by the difference relation
𝑧𝑛+1 = 𝑧𝑛 − 𝑓(𝑧𝑛
)
𝑧𝑛 − 𝑧𝑛−1
𝑓(𝑧𝑛
) − 𝑓(𝑧𝑛−1)
.
Figure 1: An example of fractals for the function
𝑓(𝑧) = 𝑧
3 − 1 in the square with bottom left-corner −1 − 𝑖 and width 2.
Typically, if 𝑧𝑛 converges and lim𝑛→∞
𝑧𝑛 =: 𝑧∗
, then 𝑓(𝑧∗) = 0.
Some methods of finding the roots (Newton-Raphson) require knowing the derivative of 𝑓. Whilst there are
numerical tricks to accomplish this, this problem is somewhat beyond the scope of this course. Instead, you
will use the Secant method which does not require the derivative, however it does require two initial values.
We will consider a polynomial 𝑃 ∈ ℂ[𝑧]; i.e.
𝑃(𝑧) = 𝑎0 + 𝑎1𝑧 + 𝑎2𝑧
2 + ··· + 𝑎𝑛𝑧
𝑛
Where 𝑎𝑘 ∈ ℂ.
1.1 Secant Fractals
One of the most fascinating aspects of this problem arises from a very simple question: given two starting
positions 𝑧0, 𝑧1 ∈ ℂ, which root does the sequence produced by Secant converge towards? It turns out that
the answer to this question is very hard!
− 1 1
Re( z)
− 1
1
− 1 1
Re( z)
MA117 Programming for Scientists: Project 2 Deadline: 12pm, Friday 19th March 2021
3
Figure 1 shows two examples of how we might visualise this for the polynomial 𝑓(𝑧) = 𝑧
3 − 1. Recall that
the roots of this polynomial are 𝑎𝑘 = 𝑒
2𝜋𝑖𝑘
3 for 𝑘 = 1,2,3 (i.e. the third roots of unity). Each of the three
colours represents one of these roots. In the left-hand figure, we colour each point depending on which root
the method converges to. The right-hand figure is the same, asides from the fact that we make the colour
darker as the number of iterations it takes to get to the root within a tolerance 𝜀 increases. The resulting
images are examples of fractals, which you have undoubtedly seen before.
Don’t worry if all of this seems quite difficult – the main aim of the assignment is for you to successfully
implement the Secant scheme. Most of the code to deal with drawing and writing the images will be given
to you.
1.2 Summary
Your task then involves several distinct elements. You will:
• write a class to represent complex numbers;
• write a class to represent a polynomial in ℂ[𝑧];
• implement the Secant method to find the roots of the polynomial;
• investigate some interesting fractals and draw some pictures!
2 Programming instructions, classes in your code and hints
On the course web page for the project, you will find the following files, which should serve as templates and
should help you to start with the project. As with the previous projects, the files have some predefined
methods that are either complete or come with predefined names and parameters. You must keep all names
of public objects and methods as they are in the templates. Other methods have to be filled in and it is up
to you to design them properly. The files define three basic classes for your project:
• Complex.java: represents points 𝑧 ∈ ℂ;
• Polynomial.java: represents polynomials in ℂ[𝑧];
• Secant.java: given two initial Complex points 𝑧0, 𝑧1 close to the root calculate the corresponding
root of Polynomial by Secant, if possible;
• SecantFractal.java: will generate a fractal similar to the one pictured above in a square.
These classes are documented in more detail in the following sections. You should complete them in the
order of the following sections, making sure to carefully test each one with a main function.
2.1 Complex
Complex is the simplest of the classes you will need to implement and will represent complex numbers. In
fact, it bears a striking resemblance to the CmplxNum class you (hopefully) implemented in week 14.
They are not identical however, so you should carefully copy and paste your code into this new class.
MA117 Programming for Scientists: Project 2 Deadline: 12pm, Friday 19th March 2021
4
2.2 Polynomial
The Polynomial class is designed to represent a polynomial 𝑃(𝑧) = ∑ 𝑎𝑛𝑧
𝑁 𝑛
𝑛=0
. As such, it contains
coeff, an array of Complex coefficients which define it. It is assumed that coeff[0] corresponds to 𝑎0,
coeff[1] to 𝑎1 and so forth. To complete this class, you will have to:
1. Define appropriate constructors. There are two that need implementation; a default constructor
which initialises the polynomial to the zero polynomial (i.e. 𝑎0 = 0), and a more general constructor
which is passed an array of Complex numbers {𝑎0,𝑎1,… , 𝑎𝑁} which should be copied into coeff.
In addition, you should ensure that if any of the leading co-efficients are zero then they are not copied.
For example, if the constructor is passed the complex numbers {𝑎0, 𝑎1,0, 0} then it should
copy{𝑎0,𝑎1
} to coeff. (When testing for equality to zero, do not use any tolerances.)
2. Return the degree of the polynomial. Recall that 𝑑𝑒𝑔 𝑓 = 𝑁.
3. Evaluate the polynomial at any given point 𝑧 ∈ ℂ. Note that you should not implement a pow
function inside Complex as it is unnecessary and inefficient. Instead, notice that (for example)
𝑃(𝑧) = 𝑎0 + 𝑎1𝑧 + 𝑎2𝑧
2 + 𝑎3𝑧
3 = 𝑎0 + 𝑧[𝑎1 + 𝑧(𝑎2 + 𝑧𝑎3)].
∆z
Figure 2: A 5x5 pixel image representing the square with top left corner
−1 + 𝑖 and bottom right corner 1 − 𝑖. The centre of each pixel represents a
complex number on the plane.
2.3 Secant
This class will perform the Secant algorithm. There are two constants defined in this class:
• MAXITER: the maximum number of iterations to make; that is, you should generate the sequence 𝑧𝑛
for 0 ≤ 𝑛 ≤ MAXITER and no more.
• TOL: At each stage of the Secant algorithm, we must test whether a sequence converges to a limit. In
this project, we will say that 𝑧𝑀 approximates this limit if, at any stage of the algorithm, |𝑧𝑀 − 𝑧𝑀−1
| <
TOL . We then say that the starting points 𝑧0, 𝑧1 required 𝑀 iterations to converge to the root.
MA117 Programming for Scientists: Project 2 Deadline: 12pm, Friday 19th March 2021
5
Additionally, you will need to define the iterate function. This accepts two parameters, 𝑧0, 𝑧1, which defines
the initial condition of the Secant difference relation, and performs the root finding algorithm. There are
three things that can occur during this process:
• everything is fine and we converge to a root;
• the difference |𝑓(𝑧𝑛
) − 𝑓(𝑧𝑛−1
)| goes to zero during the algorithm;
• we reach MAXITER iterations.
If any of the last two cases occur, then you set the error flag err to be −1 and −2 respectively; otherwise, err
is set to zero. Here is a quick example of how Secant should be used:
Complex[] coeff = new Complex[] { new Complex(-1.0,0.0), new Complex(),
new Complex(), new Complex(1.0,0.0) };
Polynomial p = new Polynomial(coeff);
Secant n = new Secant(p);
n.iterate(new Complex(), new Complex(1.0, 1.0));
System.out.println(n.getRoot());
This will print out the root of 𝑓(𝑧) = 𝑧
3 − 1 obtained with the starting point 𝑧0 = 0, 𝑧1 = 1 + 𝑖.
2.4 SecantFractal
SecantFractal will be responsible for drawing images of the fractals we saw in figure 1. However, let us
briefly consider how images are represented on computer first. A two-dimensional image is, in general,
broken down into small squares called pixels. Each of these is given a colour, and there are generally many
hundreds of pixels comprising the width and height of the image.
An example of this can be seen in figure 2. This image (badly) represents a square in the complex plane with
top-left corner −1 + 𝑖 and bottom-right corner 1 − 𝑖. In SecantFractal you will generalise this concept
to visualise squares with a top-left corner origin and width width, stored as instance variables inside
SecantFractal. The image will be of size NUMPIXELS by NUMPIXELS. Each pixel can be accessed by using
an ordered pair (𝑗, 𝑘) where 𝑗 is the row number, 𝑘 the column number and (0,0) is the top left pixel, with
0 ≤ 𝑗, 𝑘 < 𝑁𝑈𝑀𝑃𝐼𝑋𝐸𝐿𝑆. The image itself will be generated using createFractal, which accepts a
single argument colourIterations. When true, the function generates a figure like the right-hand
side of figure 1.
To complete the class, first ensure that you call the setupFractal function at the end of your constructor.
This will initialise the more complex drawing objects. It also checks that the polynomial you have given it has
3 ≤ 𝑑𝑒𝑔 𝑝 ≤ 5 . You will not need to consider any other polynomials in this class. Then inside
createFractal, use the following logic:
1. Copy colourIterations to the instance variable.
2. Iterate over each pixel at position (𝑗, 𝑘). Then translate this position to a complex number using
pixelToComplex, which uses the simple mapping (𝑗, 𝑘) ↦ 𝑜𝑟𝑖𝑔𝑖𝑛 + Δ𝑧(𝑗 − 𝑖𝑘).
3. Use 0 and this complex number as the starting points to run through the Secant algorithm.
MA117 Programming for Scientists: Project 2 Deadline: 12pm, Friday 19th March 2021
6
4. Check to see whether you’ve found this root already. You will store the list of already found roots inside
the ArrayList roots. This is the purpose of the findRoot function. In this formulation, two
complex numbers 𝑧1 and 𝑧2 are equal if |𝑧1 − 𝑧2
| < Secant. TOL.
5. Finally, colour the pixel using the colourPixel function.
After you are done, you can save the image using saveFractal. Here is an example from start to finish,
which creates the two images of figure 1. Note that your filename should end with .png:
SecantFractal f = new SecantFractal(p, new Complex(-1.0,1.0), 2.0);
f.createFractal(false);
f.saveFractal("fractal-light.png");
f.createFractal(true);
f.saveFractal("fractal-dark.png");
You should then create a document which is precisely one page long. In this document, pick a polynomial
𝑃(𝑧), a square in the complex plane and use your program to generate the two plots. You should call this file
Fractal.pdf and ensure it is saved as a PDF file.
3 Submission
You should submit, using the Tabula system, the following four files: Complex.java,
Polynomial.java, Secant.java, SecantFractal.java and Fractal.pdf which contains
your plots.
There will be a large number of tests performed on your classes. This should allow for some partial credit
even if you don’t manage to finish all tasks by the deadline. Each class will be tested individually so you may
want to submit even a partially finished project. In each case, however, be certain that you submit Java files
that compile without syntax error. Submissions that do not compile will be marked down.
If you submit a code and later (before the deadline) you realise that something is wrong and you want to
correct it, you may do so. You can submit as many versions as you wish until the deadline. However, only the
last submission will be tested. Each new submission replaces the previous one, so in particular, you MUST
submit all files required for the project even if you corrected only a single file.
Keep back-up copies of your work. Lost data are not a valid excuse for missing the deadline.
软件开发、广告设计客服
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
软件定制开发网!