Question: The question supposed to be solved in python. Objective This problem will guide you through the implementation a Python function that computes the derivatives f0,f1,,fN
The question supposed to be solved in python.


Objective This problem will guide you through the implementation a Python function that computes the derivatives f0,f1,,fN of an input function given by its values f0,f1,,fN on nodes x0,x1,,xN using 4th order compact finite differences. Suppose we have a differentiable function f(x) defined for x[0,L]. We will start by first discretizing the domain into N segments of same width x=L/N. This leads to N+1 equidistant nodes: xi=ixfori=0,,N Nodes x0 and xN are called boundary nodes. The remaining nodes are called internal nodes. To find the derivatives fi at the nodes xi using 4 -th order compact finite differences, we must solve the following system of equations: 110002410001400001000014200011f0f1f2fN1fN=x125f0+2f1+21f23(f2f0)3(f3f1)3(fNfN2)25fN2fN121fN2 For more details on the origin of these equations refer to the background section below. Notice that the matrix above is tridiagonal. Therefore we can use a tridiagonal solver to invert this system quickly and efficiently. This will be the main task of this assignment. Tasks (a) Implement a tridiagonal solver in Python. The function to implement must be called tri_solver, with input/output as described in the template. A tri-diagonal solver is a simplified Gaussian elemination solver that makes use of the banded nature of the matrix to reduce the amount of storage and computation required. We give you the following pseudo-code to get started: % Input: %l(0:N1) - array of size N containing lower diagonal %u(0:N1) - array of size N containing upper diagonal %d(0:N) - array of size N+1 containing main diagonal %b(0:N) - array of size N+1 containing the right hand side. (b) Implement a function called compute_derivative that computes the derivative using 4th-order compact finite-differences. Refer to the template for details on input/output of this function. This function will use tri_solver coded in part (a) to solve the system (). (c) Consider the test function f(x)=sin(5x)for0x3. Compute the derivatives of f using your function from 4b ) on a grid with N=16 segments (x0=0,x1=3/16,x2=23/16,,x16=3). On the same figure, plot your numerically obtained derivative alongside the exact derivative of f evaluated at the nodes x0,,x16. (d) Plot the numerical solution with N=32,64, and 128 . How does the agreement with the analytical solution change? (e) Conduct a performance study of your function compute_derivative by timing the code execution with N=10,100,1000,5000,10000. Plot mesh size versus time. Briefly discuss your results. Background This section provides background information on the origin of the system ( ) for students interested in learning more about numerical methods. However, familiarity with the details presented here is not required to complete the assignment. For a basic finite-difference scheme, an n-th order approximation of the derivative fi=f(xi) can be obtained using a linear combination of the values of f at neighboring points. E.g., second and fourth order approximations are obtained using: (2ndorder)fi(4thorder)fi=2x1(fi+1fi1)+O(x2)=12x1(fi28fi1+8fi+1fi+2)+O(x4) The problem with these schemes is that high-order approximations require increasingly large stencils (i.e, involving increasingly more neighboring points). 4 Compact finite difference schemes can achieve the same order of accuracy, but on smaller stencils. This has many computational advantages that go beyond the scope of this problem. To build a compact approximation of fi=f(xi), we must use the values of f and the derivatives f from neighboring points. For a fourth order scheme, we must linearly combine fi,fi+1,fi1,fi+1, and fi1 such that fi+a0fi+a1fi+1+a2fi1+a3fi+1+a4fi1=O(x4) To find the coefficients a0,a1,a3, and a4, we introduce the Taylor series expansions f and its derivative f at neighbohring points xi+1 and xi1 in the equation above, and cancel orders 0 to 4 . These Taylor series expansions are: fi+1fi1fi+1fi1=fi+xfi+2x2fi+6x3fi+24x4fi(iv)+120x4fi(v)=fixfi+2x2fi6x3fi+24x4fi(iv)120x4fi(v)=fi+xfi+2x2fi+6x3fi(iv)+24x4fi(v)=fixfi+2x2fi6x3fi(iv)+24x4fi(v) Canceling orders 0 to 4 leads to the following equations a0+a1+a2a1xa2x+a3+a4a12x2+a22x2+a3xa4xa1nxa2nx+a3+a4=0=1=0=0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
