Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Questions - MATLAB Task

The document outlines a MATLAB assignment involving the Adams-Bashforth integration schemes for ODEs, the vibration of a circular drum skin governed by the wave equation, and heat transfer in a spherical shell using the diffusion equation. It includes multiple questions that require deriving numerical methods, implementing finite difference equations, and solving eigenvalue problems. The assignment emphasizes showing all working, writing MATLAB functions, and plotting results to analyze the behavior of the systems described.

Uploaded by

Kumail Raza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Questions - MATLAB Task

The document outlines a MATLAB assignment involving the Adams-Bashforth integration schemes for ODEs, the vibration of a circular drum skin governed by the wave equation, and heat transfer in a spherical shell using the diffusion equation. It includes multiple questions that require deriving numerical methods, implementing finite difference equations, and solving eigenvalue problems. The assignment emphasizes showing all working, writing MATLAB functions, and plotting results to analyze the behavior of the systems described.

Uploaded by

Kumail Raza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Q UESTION 1 [10 M ARKS TOTAL ]

Background – Adams-Bashforth schemes

The Adams-Bashforth integration schemes are one of the many ways to find solutions of the ODE
dy/dt=f (t,y). In particular they aim to find the integral in the update

Eqn 1
They are based on the following set of steps
1. fit a polynomial to a set of known data points (ti-n , fi-n), (ti-n+1, fi-n+1), … (ti, fi)
2. integrate this polynomial over the single interval ti, ti+1.
The underlying idea is that the polynomial fitting uses information in the “past” to provide a better
information of what is happening over the current step (i.e. ti to ti+1). See Workshop 19 for more
detail.
Q1
Using three points equally spaced in time, (ti-2, ti-1, ti) and the associated function values (fi-2, fi-1, fi),
derive the Adams-Bashforth (AB3) scheme for estimating the integral on the RHS of Eqn 1.
Hints: You don’t have to do it the way I suggest below, but this is how I would approach this
question:
1. Let the (constant) spacing in time be equal to h
2. Without loss of generality (WLOG), shift your time axis so that ti-1 = 0.
3. Fit a quadratic polynomial to the (t, f ) points, i.e. let f = At2+Bt+C (determine A, B, C in terms
of h and fi-2, fi-1, fi)
4. Analytically integrate the resulting polynomial over the time interval [ti, ti+1]
5. Write the resulting formula for the AB3 update (i.e. Eqn 1)

SHOW ALL YOUR WORKING in your PDF

Q UESTION 2 [10 M ARKS TOTAL ]

Background
The vibration of a circular drum skin is governed by the wave equation. The solution of the wave
equation U (r,q ,t) can be written as a product of three terms
U(r, q , t) = Y (r) Q(q ) G(t) ,
where U is the vertical displacement of the skin. Using separation of variables in cylindrical polar
coordinates, it can be shown that for each azimuthal wave mode (Qn(q )) the equation that governs
the radial “shape” of the skin is given by

MATLAB Assignment Page 3 of 9


d 2Y 1 dY æ 2 n 2 ö
+ + k - 2 ÷Y = 0 (1)
dr 2 r dr çè r ø

The solution of equation 1 for the drum skin is given by the nth order Bessel function of the first kind,
Y(r) = Jn(kr) where where k is an eigenvalue that has many possible values. When the mode is
axisymmetric, (i.e. Q(q ) = constant) then n = 0 and the equation becomes

d 2Y 1 dY
+ + k 2Y = 0 (2)
dr 2 r dr
with solution given by the 0th order Bessel function of the first kind Y(r) = J0(kr).
The aim of this question is to determine the first 4 eigenvalues of the solutions to equation 2 and to
plot their mode shapes. You are given the following information:
 The drum skin has a radius of 1, and is clamped here (i.e. Y(1)=0).
 The boundary conditions at r=0 are:
o the derivative of Y at the origin MUST be zero (i.e. Y’(0) = 0).
o The magnitude of Y at the origin (i.e. Y(0)) specifies the amplitude of the oscillation – it
does not affect the mode “shape”. Different values of Y(0) will just scale the shape by a
linear factor. Hence when n = 0, we can arbitrarily set Y(0) = 1 (WLOG).
 The term (1/r) dY/dr is a problem at the origin. L’Hopital’s rule1 should be used to replace this
term, but ONLY AT THE ORIGIN where the problem lies (i.e., the ODE, and the set of 1 st order
ODES, AT the original must be modified in MATLAB for the first nodal point (r=0) only).
Workshop 17 will provide some assistance with this problem.
Q2a
In your PDF, write the centered finite difference equation that approximates this equation at an
arbitrary point, ri assuming a uniform mesh spacing, h.
Q2b
Using the relaxation method and a mesh spacing of h=/4, by hand explicitly write the matrix
equation that approximates the eigenvalue problem at the origin AND the 3 internal nodes (replace
h by ¼ in the matrix system). Assume that the specified BCs are dY/dr = 0 at r = 0 and Y = 0 at r = 1.
You will need to change the ODE AT the origin using L’Hopital’s rule AND approximate the derivative
BC here using centered finite differences. Your system should be a 4x4 matrix problem for unknowns
defined at x = 0, 0.25, 0.5 and 0.75 and the matrix should not contain any symbols at all, just
numbers.
DO NOT ATTEMPT TO SOLVE THE SYSTEM

Q2c
Write the second order equation (Eqn 2) as two first order equations that can be solved using one of
the ODE integrators we have considered in this unit given a value of k. NOTE, the ODE will look

1 L’Hopital’s rule states that IF f(x0)=0 and g(x0)=0, then lim xx0 f(x)/g(x) = f’(x)/g’(x)
MATLAB Assignment Page 4 of 9
different at r=0 because you will have used L’Hopital’s rule to replace the (1/r) dY/dr term here.
Clearly specify what boundary conditions or constraints you will need to use at r=0 in your numerical
integration, and what boundary condition (or constraint) you want to satisfy at r = 1. Your
adjustable parameter is the eigenvalue k

Q UESTION 3 [20 M ARKS TOTAL ]

Q3a
Write a function that calculates the RHS function for the set of ODE equations you found in Q2c.
This function MUST calculate the function when r = 0 and when r  0 separately, thus an anonymous
function (function handle) cannot be (easily) used.
This function should have a header like
function [f] = ODERHS(r,y,k)
where the input parameters are
 r - radius (scalar value, not a vector) at which the RHS is being calculated
 y - a column vector of the unknowns at this radius (y1, y2)T
 k - current estimate of the eigenvalue
and the output parameter is
 f - a column vector of RHS values for the equations.

Q3b
Using ANY accurate ODE solver (I suggest your RK4A code from Lab 04, but feel free to use ODE45 if
you like) write a MATLAB function that returns a RHS estimate of Y(r=1) given a guess for the
eigenvalue (i.e. it integrates the system of 1 st order ODEs that is equivalent to Eqn 2 from r = 0, to
r =  given a guess for the eigenvalue k).
This function should have ONLY a single parameter (the eigenvalue guess) so that it can be used in a
generic root finding algorithm. There are several ways to do this. For example
1. A MATLAB function with a header like

function [RVal] = BVal(k)

where the single input parameter is k – the eigenvalue guess and the output parameter is
RVal - a scalar value that is the estimate of Y at r =  for the given k. In this approach, the
initial condition (Y0), the range of integration [0,1] and the desired tolerance need to be made
available INSIDE BVal (e.g. by using global variables). You will need to use RK4A (or ODE45)
and ODERHS (from Q3a) inside BVal to solve the eqn..

MATLAB Assignment Page 5 of 9


2. OR by writing a MATLAB function (e.g. call ODE_Solve) that includes ODERHS, the range,
eigenvalue, etc. as input parameters and then writing a “wrapper” anonymous function like
done in workshops, e.g.

BVal = @(k) ODE_Solve(ODERHS, range, k, tol)

There are no doubt other ways you can do this that will also work – choose whatever way you like.

Q3c
Modify the template in Lab05_Q3.m so that it calculates the RHS value of Y at r = 1 for values of k in
the range k [0,20]. (Choose as many values as you think are needed to make a good plot).
Plot the predicted value of RVal as a function of k for values of k in the range k [0,20].

Q3d
Recall that the eigenvalues of Eqn 2 are those values of k which satisfy the correct BC at r =  after
we have integrated from r = 0, i.e. they are the roots (zeros) of the function specified by BVal(k).
Modify the template in Lab05_Q3.m so that it finds the first 4 eigenvalues of the equation
automatically (i.e. using MATLAB code, not your eyes).
Print the first 4 eigenvalues to the command window to 5 decimal places and with suitable
identification (i.e. don’t just write 4 numbers).
HINT: One way to do this is to use the data you calculated in Q3c to determine when RVal changes
sign and use the corresponding values of k as bounds in a bracketed root finding method such as
bisection. If you have a different way to find the roots, you can use it provided you write a brief
statement to the command window outlining your method. HOWEVER, whatever method you use,
it must not require human intervention to find the roots and must be entirely contained in the
algorithm logic.

Q3e
For the first, second and fourth eigenvalue, calculate the associated eigen-solutions and plot them in
a single figure with a solid line (a different colour for each).

HINT: Although not generally desirable, it might be useful to declare some global variables like the
initial condition (Y0), the range of integration [0,1] and the desired tolerance and use these across
some of the functions in this question.

MATLAB Assignment Page 6 of 9


Q UESTION 4 [10 M ARKS TOTAL ]
Background
Transfer of heat in a spherical shell (for example the Earth’s mantle) is in part, governed by the 1-D
diffusion (or heat) equation in spherical polar coordinates:

¶q æ 1 ¶ æ ¶q ö ö
= k ç 2 ç r2 ÷ ÷
¶t è r ¶r è ¶r ø ø
(3)
æ ¶ 2 q 2 ¶q ö
= kç 2 +
è ¶r r ¶r ÷ø

In eqn 3, k is a diffusion coefficient (k > 0). You will solve this equation on a domain R1 ≤ r ≤ R2 with
boundary conditions at r = R1 given by ∂q/∂r = 0 and the BC at r = R2 given by q=0. The initial
condition is a constant q = q0.

Q4a
By hand, write the forward in time, centred in space (FTCS) difference equation that approximates
equation (3). What is the temporal and spatial order of accuracy of this discretization?

Q4b
Undertake a von Neumann stability analysis for this difference equation (you can assume that the
error satisfies the same difference equation as the solution for q, because it does). Consider just
ONE Fourier mode of the representation of the error, and write it in the simplified form

e nj = AneiKjd r
You do NOT need to derive the stability criterion, but you DO need to write an expression for the
amplification factor (i.e. the ratio of error at time n+1 to that at time n). It will be a complex
number.

Q4c
Repeat Q4a and 4b for the BTCS scheme

Q UESTION 5 [15 M ARKS TOTAL ]


Q5a
Write a MATLAB function that updates the solution vector q by ONE TIMESTEP using the FTCS
scheme (it will be a short function). Ensure that your function has the function header
function [q_new] = ftcs_step(q,dt,r,dr,k)

MATLAB Assignment Page 7 of 9


where the input values are
 q is the vector solution at the current time (time=n)
 dt is the timestep
 r is a vector that contains the radial values of the grid points from R 1 to R2
 dr is the spatial step
 k is the coefficient of thermal diffusivity
and the output is
 q_new is the new (time = n+1) solution of q.

The initial condition is given by q(r,0) = q0. The boundary condition at r = R2 (q=0) is easily
implemented by setting q(R2) = 0 for all time. However you will need to set the boundary condition
at r = R1 (i.e. ∂q/∂r = 0) by using a finite difference approximation to the derivative. To maintain
the order of accuracy of your overall scheme, you should use centered differences for this derivative
AND keep (and solve) the difference equation for q(R1). See Workshop 21 for assistance on this.

Q5b
Consider a steel shell that is 4m in diameter with 1m thick walls (i.e. R 1=1 m, R2=2 m) at an initial
temperature everywhere of q0 = 1000C. The temperature on the surface of the sphere is held at
0C. The coefficient of thermal diffusivity for steel k = 1.2e-5 m2/s
Modify the template in Lab05_Q5.m using the above values for your parameters to solve Eq 3 using
the FTCS scheme that you have written in Q5a. Discretise your domain with 100 intervals (i.e. 101
nodes).
From the lecture and workshop notes, you know what the stability timestep restriction is on the 1D
heat equation IF you were to use Cartesian coordinates – calculate this value in your code and call it
dtStab.
Integrate forward in time from the initial condition to t=48 hours (your time scale in the solution is
in seconds) with timesteps of: [0.5*dtStab, dtStab and 1.001*dtStab].
 For each different choice of timestep, plot the solution at times given by t = 0, 1.0, 2.5, 5, 10,
24, 48) HOURS on the same plot (i.e. you should have 3 plots, each with 7 curves).
(DO NOT be concerned about ensuring the plots are at EXACTLY these times, although they
should be close. For this lab, near enough in time is good enough.)
Write a brief statement to the command window that describes what you observe in each plot.
Considering the stability criterion for the Cartesian version of the heat equation, state whether you
think it is also useful for the heat eqn in spherical coordinates. Why or why not? Propose a reason
as to why you get this result.

MATLAB Assignment Page 8 of 9


Q UESTION 6 [15 M ARKS TOTAL ]
Repeat Question 5 with the following modifications
 Use a backward in time, centred in space (BTCS) discretization (write function BTCS_step)
 Choose time steps of [dtStab, 10*dtStab and 100*dtStab] and solve, plotting as in Q5
 Write a comment that describes what you see - is this what you expect?
For each timestep, you will need to set up a matrix problem that is inverted to find the solution. You
may solve this matrix problem any way you like.

Poor Programming Practices [-10 Marks]


(Includes, but is not limited to, poor coding style or insufficient comments or
unlabeled figures, etc.)

(END OF LAB)

MATLAB Assignment Page 9 of 9

You might also like