联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Matlab编程Matlab编程

日期:2018-10-13 10:30

Updated Assignment Sheet 5 of MTH2051/3051

Instructions: Your completed assignment must be handed to your tutor before

4pm on Friday of week 11. The code for the programming exercises as well as relevant

output are to be submitted as part of your hardcopy submission. In addition,

collect all your Matlab files in one file firstname_surname_assignment_5.zip and

submit this file through Moodle. The Moodle submission is due at the same time as

the hardcopy submission. Non-executable code will not be marked.

Assignment 5.1. (numerical quadrature, to be attempted by 2nd and 3rd

year students, 19 marks)

In this exercise, you will learn in a hands-on manner how numerical quadrature

works and how the degree of exactness of a quadrature formula impacts

the behaviour of the composite quadrature rule.

a) Write a function qf=numquad(f,a,b,quadtype) in Matlab which approximates

the integral R b

a

f(x) dx with quadrature rule quadtype. Your

method should be able to process the quadrature rules ’midpoint’,

’trapezoidal’, ’Simpson’ and ’Gauss2’, where the latter means the

Gauss quadrature with two nodes from the lectures/notes.

b) Apply your function from task a) to the integral R π

0

sin(x) dx, testing

all quadrature types requested in part a).

c) Write a function qf=compquad(f,a,b,N,quadtype) in Matlab which

approximates the integral R b

a

f(x) dx with a composite quadrature rule

of type quadtype applied to N subintervals. Make the same quadrature

rules available as in task a).

d) Compute the integral R π

0

sin(x) dx by hand.

e) Approximate the integral R π

0

sin(x) dx with your function from task c)

for N = 1, 2, 4, 8, 16, 32, 64, 128, 256. Plot the absolute values of the

errors of all methods requested in part a) against h = π/N into one

log-log diagram.

f) Restate the error estimate for composite quadrature.

g) Relate your diagram from task e) to the theorem from task f).

1

Assignment 5.3. (explicit versus implicit methods, to be attempted by 2nd

and 3rd year students, 28 marks)

In this exercise, you will learn about the limits and benefits of explicit and

implicit Runge-Kutta methods.

a) Implement a function [X,Y]=explicit_Euler(f,y0,a,b,N), which

approximates the solution of the initial value problem

(x) = f(x, y(x))x ∈ (a, b), y(a) = y0

by N steps of the explicit Euler scheme.

b) Implement a function [X,Y]=implicit_Euler(f,y0,a,b,N), which

approximates the solution of the above initial value problem by N

steps of the implicit Euler scheme. For the solution of the nonlinear

equations, you may use your own code or the Matlab function fsolve.

We need a bit of theoretical preparation to do the next steps.

c) State the convergence theorem for the explicit Euler method.

d) State the convergence theorem for the implicit Euler method.

Now we will investigate both schemes on the simple scalar equation

y

0

(x) = y(x) x ∈ (0, 5), y(0) = 1. (1)

The right-hand side is 1-one-sided Lipschitz and 1-Lipschitz, so all our theory

from the lectures/notes applies. In particular, equation (1) has a unique

solution.

e) Compute the solution of equation (1) by hand and work out its first

and second derivative.

f) Deduce error estimates for the explicit and implicit Euler schemes in

the particular situation of equation (1).

g) Apply the explicit and the implicit Euler schemes to equation (1). Create

three diagrams for the explicit Euler scheme and three diagrams for

the implicit Euler scheme with N = 5, 50, 500, all with x on the first

and y on the second axis. Into each, plot

2

– the numerical solution and

– two lines (above and below the numerical solution) between which

the real solution must be located according to the error estimate.

h) Comment on your results. Does it pay off to use the more expensive

implicit Euler scheme?

Now we will investigate both schemes on the simple scalar equation

y

0

(x) = y(x)x ∈ (0, 5), y(0) = 1. (2)

The right-hand side is ?1-one-sided Lipschitz and 1-Lipschitz, so all our

theory from the lectures/notes applies. In particular, equation (2) has a

unique solution.

i) Compute the solution of equation (2) by hand and work out its first

and second derivative.

j) Deduce error estimates for the explicit and implicit Euler schemes in

the particular situation of equation (2).

k) Apply the explicit and the implicit Euler schemes to equation (2). Create

three diagrams for the explicit Euler scheme and three diagrams for

the implicit Euler scheme with N = 5, 50, 500, all with x on the first

and y on the second axis. Into each, plot

– the numerical solution and

– two lines (above and below the numerical solution) between which

the real solution must be located according to the error estimate.

l) Comment on your results. Does it pay off to use the more expensive

implicit Euler scheme?

3

Assignment 5.4. (asymptotic stability and oscillations, to be attempted

by 3rd year students only, 12 marks)

An abstract example from the lectures/notes shows that the asymptotic behaviour

of a numerical method on linear scalar equations determines their

asymptotic behaviour on diagonalisable systems of linear equations. Let us

comprehend this and a bit more through numerical simulation. The initial

value problem

can be diagonalised, which yields the system

(4)

of decoupled linear scalar equations.

a) Approximate the solution of equation (3) with the explicit Euler scheme,

using N = 49, N = 50, N = 51 and N = 10000 steps and plot all solutions

into separate diagrams. Make sure your titles, axis labels and

legends are accurate.

b) Approximate the solution of equation (4) with the explicit Euler scheme,

using N = 49, N = 50, N = 51 and N = 10000 steps and plot all solutions

into separate diagrams. Make sure your titles, axis labels and

legends are accurate.

The numerical instability for N ≤ 49 and the oscillations are typical for an

explicit method failing to capture contractive behaviour of the flow. They

appear in the original system if and only if they appear in at least one

component of the diagonalised system. (This is why the behaviour of a

method on the scalar test equation tells you so much about it.) As you see,

their presence makes the entire numerical computation worthless.

c) Repeat the computations from tasks a) and b) with the implicit Euler

scheme, using N = 8, N = 16, N = 32 and N = 64 steps.

Part d) is removed.

4

Assignment 5.5. (Applications, to be attempted by 2nd and 3rd year students,

7 marks)

In this exercise, you will study an elementary, but interesting example numerically.

We will not discuss existence, uniqueness and asymptotic behaviour,

but keep in mind that in principle we would have to do that.

a) The Lotka-Volterra equation from mathematical biology models the

time evolution of coexisting predator and prey populations denoted v

and u. It is assumed that their numbers or biomass are so large that

they can be considered continuous functions in time. In this talk, we

will focus on the particular equation

(5)

which is motivated by the following reasoning.

– If the prey is left alone and not limited by availability of food,

then it will grow exponentially according to the law u

0 = u.

– Predator and prey meet with a certain probability, and in this case,

the prey is consumed by the predator, i.e. the prey population

shrinks and the predator population grows with a rate 3

10u(x)v(x).

– The predators lose biomass over time with a rate 12v(x).

To obtain an understanding of this system, do the following.

– Write a function f=Lotka_Volterra(x,y) in Matlab, which returns

the right-hand side of equation (5).

– Apply your function to the data x = 0 and y = (2,12).

– Solve equation (5) numerically on the interval [0, 30] with initial

values (2,k2), k = 1, . . . , 6. Use the Matlab function ode45 to

generate the solutions. Use the Matlab function odeset to set a

relative error tolerance of 10?3

, an absolute error tolerance of 10?5

and a maximal time-step of 10?2

. (Internally, the function ode45

works in a similar way as the adaptive quadrature from a previous

exercise.) Then create a plot with two panels.

Create a phase plot (u against v, without time component)

containing all numerical solutions in the first panel.

5

Plot both components u and v of the solution corresponding

to k = 1 against time in the second panel.

Create titles, axis labels and legend to support the message of

your plots. Save your code as a Matlab script visualise_LV.

– Describe your observations briefly.

The other parts have been removed.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp