1. Homepage
  2. Programming
  3. Computing and Numerical Methods 1 Part 2: Numerical Methods Coursework: Bessel functions

Computing and Numerical Methods 1 Part 2: Numerical Methods Coursework: Bessel functions

Engage in a Conversation
Bessel functionsMatlabComputing and Numerical Methods 1Numerical Methods

Computing and Numerical Methods 1 CourseNana.COM

Part 2: Numerical Methods CourseNana.COM

Completing this live file CourseNana.COM

You will submit only this self-contained completed livefile.No other scripts or other files will be marked. When completing this livefile: CourseNana.COM

·       Please make sure all of your code is formatted as code using the "code" button on the Live Editor ribbon; CourseNana.COM

·       Please make sure anything that is not code or code comments is formatted as text; CourseNana.COM

·       Marks for each section and sub-section are shown in bold square brackets; CourseNana.COM

·       Ensure that the entire livefile runs without errors or warnings before submitting! CourseNana.COM

Code CourseNana.COM

All code you write must have a comment clearly explaining what each line does. Comments should be brief but clear. CourseNana.COM

All local functions must: CourseNana.COM

·       be entered in the Functions section at the bottom of this livefile; CourseNana.COM

·       be named correctly according to the guidance below; CourseNana.COM

·       have a comment on each line of code explaining its function and how it relates to the equations in the handouts or other theory; CourseNana.COM

·       NOT call built-in MATLAB functions from outside the standard MATLAB toolbox C:\Program Files\MATLAB\R2022b\toolbox\matlab (but you may use these to check your functions). CourseNana.COM

To check the toolbox of a MATLAB function use the which command. The short name of the toolbox is shown after "toolbox\" For example: CourseNana.COM

which spline CourseNana.COM

returns C:\Program Files\MATLAB\R2022b\toolbox\matlab\polyfun\spline.m which means it is in the standard MATLAB toolbox, whereas CourseNana.COM

which fit CourseNana.COM

returns C:\Program Files\MATLAB\R2022b\toolbox\curvefit\curvefit\fit.m which means it is in the curvefit toolbox, and not the standard MATLAB toolbox. CourseNana.COM

Plots CourseNana.COM

You should ensure any plots you are asked to produce have: CourseNana.COM

·       axis labels; CourseNana.COM

·       x and y grid; CourseNana.COM

·       all lines/markers clearly differentiable through use of colour or line/marker type; CourseNana.COM

·       legend (where more than one dataset is plotted), placed so as to minimise overlap with data lines/markes; CourseNana.COM

·       any spaced discrete point data (such as that in the table below) plotted as points (not lines); CourseNana.COM

·       when plotting overlapping functions use solid, dashed, chain-dashed and dotted linetypes to maximise visibility of all lines. CourseNana.COM

Note that any plots that are not formatted as above (and exemplified in the Computer Labs Code livefiles) will not be marked. CourseNana.COM

Numerical outputs CourseNana.COM

Anywhere you are asked to output values you should: CourseNana.COM

·       Use one of the appropriate built-in MATLAB functions e.g. sprintf (as in the Computer Lab Codes); CourseNana.COM

·       Include a clear description of what the output variable represents; CourseNana.COM

·       Absolute errors should be presented to 3 significant figures. CourseNana.COM

Submission CourseNana.COM

·       You should submit your livefile on Blackboard by Friday 24th March 2023 at 1700. CourseNana.COM

·       Please rename the file in the format NM1_CW_XXXXXX.mlx where XXXXXX is your CID number. CourseNana.COM

·       As usual, please ensure you receive a confirmation email following submission. Only confirmed submitted files will be marked (partially complete Blackboard submissions will be ignored). CourseNana.COM

Introduction CourseNana.COM

Bessel functions describe electric fields, mechanical vibrations, heat conduction, optical diffraction and other phenomena involving cylindrical or spherical symmetry, for example the displacement of vibrating circular membranes, such as pressure transducer sensing elements and drum skins, as well as temperature distributions in heated cylindrical objects, such as combustor temperature probes and hot dogs in boiling water. The image below (source: https://commons.wikimedia.org/wiki/File:Vibrating_drum_Bessel_function.gif ) shows an animation of a vibrating drum skin. Everything you could possibly want to know about Bessel functions can be found at the DLMF: NIST Digital Library of Mathematical Functions, which is based on a famous mathemtical handbook known as "Abramowitz and Stegun", available as a pdf here. CourseNana.COM


CourseNana.COM

CourseNana.COM

CourseNana.COM

There are various different kinds of Bessel functions, including the first kind , the second kind and the third kind . For each kind there are also different orders, e.g. integers The Bessel functions of the first kind for the first five integer orders (n = 0 to 4) are plotted below, using the built-in MATLAB function besselj. They look a bit like decaying sinusoids, except for some subtle differences as we shall see. CourseNana.COM

CourseNana.COM

To see how this plot was made run the folllowing code: CourseNana.COM

openExample('matlab/PlotBesselFunctionsOfFirstKindExample') CourseNana.COM


CourseNana.COM

CourseNana.COM

Interestingly, the vertical displacement of the drumskin above is given by in polar coordinates. You should be able to see that, at a certain moment in time (e.g. at the limits of the motion), the vertical displacement plotted in the radial direction resembles in the plot above. You will learn how to obtain the full analytic solution to this sort of time-dependent differential equation later on in the undergraduate course. CourseNana.COM


CourseNana.COM

CourseNana.COM

In this coursework you are going to investigate Bessel functions of the first kind, , over the interval . CourseNana.COM


CourseNana.COM

Part 1: Interpolation [9 marks] CourseNana.COM

Bessel functions are usually not amenable to straightforward evaluation (e.g. by hand or with a standard scientific calculator) and are often compiled in standard mathematical tables. One such table is shown below: CourseNana.COM

BesselTable= array2table([... CourseNana.COM

  0             0 CourseNana.COM

0.5       0.24227 CourseNana.COM

  1       0.44005 CourseNana.COM

1.5       0.55794 CourseNana.COM

  2       0.57672 CourseNana.COM

2.5       0.49709 CourseNana.COM

  3       0.33906 CourseNana.COM

3.5       0.13738 CourseNana.COM

  4     -0.066043 CourseNana.COM

4.5      -0.23106 CourseNana.COM

  5      -0.32758 CourseNana.COM

5.5      -0.34144 CourseNana.COM

  6      -0.27668 CourseNana.COM

6.5      -0.15384 CourseNana.COM

  7    -0.0046828 CourseNana.COM

7.5       0.13525 CourseNana.COM

  8       0.23464 CourseNana.COM

8.5       0.27312 CourseNana.COM

  9       0.24531 CourseNana.COM

9.5       0.16126 CourseNana.COM

 10      0.043473... CourseNana.COM

     ], "VariableNames",["x","J"]) CourseNana.COM

BesselTable = 21×2 table CourseNana.COM

  CourseNana.COM

x CourseNana.COM

J CourseNana.COM

1 CourseNana.COM

0 CourseNana.COM

0 CourseNana.COM

2 CourseNana.COM

0.5000 CourseNana.COM

0.2423 CourseNana.COM

3 CourseNana.COM

1 CourseNana.COM

0.4400 CourseNana.COM

4 CourseNana.COM

1.5000 CourseNana.COM

0.5579 CourseNana.COM

5 CourseNana.COM

2 CourseNana.COM

0.5767 CourseNana.COM

6 CourseNana.COM

2.5000 CourseNana.COM

0.4971 CourseNana.COM

7 CourseNana.COM

3 CourseNana.COM

0.3391 CourseNana.COM

8 CourseNana.COM

3.5000 CourseNana.COM

0.1374 CourseNana.COM

9 CourseNana.COM

4 CourseNana.COM

-0.0660 CourseNana.COM

10 CourseNana.COM

4.5000 CourseNana.COM

-0.2311 CourseNana.COM

11 CourseNana.COM

5 CourseNana.COM

-0.3276 CourseNana.COM

12 CourseNana.COM

5.5000 CourseNana.COM

-0.3414 CourseNana.COM

13 CourseNana.COM

6 CourseNana.COM

-0.2767 CourseNana.COM

14 CourseNana.COM

6.5000 CourseNana.COM

-0.1538 CourseNana.COM


CourseNana.COM


CourseNana.COM

Investigate the different methods of interpolation covered in the course using the interpolant data in the above table as follows: CourseNana.COM

·       M1.1: Write a local MATLAB function called IntPoly that fits a polynomial of the maximum possible order to the tabular data using the first approach in Handout 4 involving inversion of a matrix of x-values. [1] CourseNana.COM

·       M1.2: Write a local MATLAB function called LagrangePoly to compute the interpolating Lagrange polynomial that passes through all inerpolant data points. HINT: You may find the matlab functions poly and polyval useful. [2] CourseNana.COM

·       M1.3: Write a local MATLAB function called IntSpline that performs cubic spline interpolation with natural (free-runout) end conditions. [1] CourseNana.COM

All functions should: CourseNana.COM

·       take as input a vector of query points that is evenly spread across the interval and spaced by 0.1 CourseNana.COM

·       output the evaluation of the interpolation function at the query points. CourseNana.COM

Evaluate the performance of your local functions as follows: [1] CourseNana.COM

·       E1.1: Plot the interpolated data (as a continuous curve) alongside the tabular data (as points) for all methods on a single plot. CourseNana.COM

·       E1.2: Evaluate and plot the absolute error in the interpolation compared to besselj. Plot the absolute error as a function of x for all methods on a single plot. CourseNana.COM

·       E1.3: Compute and output the time required to perform the interpolation along with the -norm of the absolute error across the interval using e.g. sprintf (as in the Computer Lab Codes) to clearly state which values relate to which method. CourseNana.COM

Questions CourseNana.COM

·       Q1.1: How does the performance of the various methods compare in terms of accuracy and computation time? [1] CourseNana.COM

·       Q1.2: Methods 1. and 2. should generate equivalent polynomials according to Handout 4. Do they? Try to explain any discrepancies. [1] CourseNana.COM

·       Q1.3: What happens to the overall error (-norm) in method 2 if, instead of using the tabular data, you interpolate data sampled directly from besselj with the same number of points (i.e. 21) but using Chebyshev spacing? [1] CourseNana.COM

·       Q1.4: Compare method 3. with the built-in MATLAB function spline. Are the outputs the same? Try to explain any discrepancies. [1] CourseNana.COM

Hints CourseNana.COM

Method M1.2: One way to approach this is to use a loop to step through the and for each one create a matrix of basis polynomial coefficients, using the built-in MATLAB function poly to find the coefficients of the (basis) polynomial whose roots are all the except one. You can then multiply this by a vector of in order to obtain the scaled basis polynomials, and then use built-in MATLAB function polyval to evaluate the resulting polynomial coefficients for the query points. CourseNana.COM

Part 1: Your Solution CourseNana.COM

% Enter your code here and your local functions at the bottom. CourseNana.COM

Enter explanation here. CourseNana.COM

Part 2: Numerical Integration [8 marks] CourseNana.COM

For integer values of n, the bessel function of the first kind may be defined in integral form using Bessel's integrals as: CourseNana.COM

CourseNana.COM

Investigate the different methods of numerical integration covered in the course to evaluate Bessel's integral for the first order Bessel Function of the first kind, as follows: CourseNana.COM

·       M2.1: Write a local MATLAB function called trapzJ1 that uses the Trapezium rule. [1] CourseNana.COM

·       M2.2: Write a local MATLAB function called simpsonJ1 that uses Simpson's 1/3 rule. [1] CourseNana.COM

·       M2.3: Write a local MATLAB function called gaussJ1 that uses Gauss-Legendre quadrature. [3] CourseNana.COM

All functions should: CourseNana.COM

·       take as input a vector x that is evenly spread across the interval and spaced by 0.1, as well as the number of points used in the integration, N. CourseNana.COM

·       output . CourseNana.COM

You should evaluate the performance of your local functions as follows [2]: CourseNana.COM

·       E2.1: Plot the approximated function alongside values computed using besselj for all methods on a single plot. CourseNana.COM

·       E2.2: Evaluate and plot the absolute error compared to besselj as a function of x for all methods on a single plot. CourseNana.COM

·       E2.3: On a single figure, plot the -norm of the absolute error across the interval vs the number of points, N, used in the integration for each method for a sensible range of N. Plot a horizontal line representing double-precision accuracy, and for each method work out how many points are required to evaluate to within machine (double) precision of besselj. CourseNana.COM

·       E2.4: Write a simple loop to evaluate the integral for the vector x using the built-in MATLAB function integral. Plot the error across the interval and evaluate the computation time required to achieve double-precision accuracy. CourseNana.COM

Questions CourseNana.COM

·       Q2.1: How does the computation time of the three methods M2.1,M2.2, M2.3 and the looped integral function compare? Do you think the function besselj uses numerical integration to evaluate Bessel functions? [1] CourseNana.COM

Hints CourseNana.COM

Method M2.1: Use the built-in MATLAB function trapz. CourseNana.COM

Method M2.2: Use an anonymous function (as in the Computer Lab Codes), that takes x and tau as the inputs, in order to define the integrand. CourseNana.COM

Method M2.3: You will need to evaluate the Legendre polynomials to higher orders than in the Class Handouts. CourseNana.COM

One way to approach this is to use the MATLAB functions conv and polyder to evaluate the definition of in Handout 3: CourseNana.COM

CourseNana.COM

The term can be evaluated using the built-in MATLAB function conv, which multiplies two polynomials and returns the coefficients of the resulting polynomial (a process known as convolution): CourseNana.COM

pn = [1 0 -1];                  % Polynomial coefficients for polynomial x^2-1 CourseNana.COM

res = 1;                        % Initialise the result CourseNana.COM

N = 3;                          % Power to which you want to calculate the input polynomial CourseNana.COM

for k1 = 1:N CourseNana.COM

    res = conv(res, pn); % conv . The first iteration will simply multiply 1 and [1 0 1] to obtain [1 0 1]. CourseNana.COM

end CourseNana.COM

% res will now be the coefficients of (x^2-1)^N expanded as a polynomial. CourseNana.COM

The coefficients of the derivative of a polynomial can be found using built-in MATLAB function polyder. You will need to code a loop similar to the one for conv to calculate the Nth derivative. Yo can also use polyder and polyval to evaluate the weights. CourseNana.COM

To obtain the roots of the polynomial based on the coefficient simply use the built-in MATLAB function roots. To evaluate a polynomial for a given vector of input values simply use the built-in MATLAB function polyval. CourseNana.COM

Another way to generate the Legendre polynomials is using Bonnet's recursion formula: CourseNana.COM

CourseNana.COM

Starting with and this allows all subsequent polynomials to be computed. For example, is found from: CourseNana.COM

. CourseNana.COM

Based on this it is possible to code a recurrence relation to calculate the ceofficients of any Legendre polynomial. To illustrate this consider the coefficients of the first few polynomials: CourseNana.COM

CourseNana.COM

L0_coeffs = 1 CourseNana.COM

CourseNana.COM

 L1_coeffs = [1 0] = [L0_coeffs 0]/1 CourseNana.COM

CourseNana.COM

 L2_coeffs = 1/2*[3 0 -1] = ( 3*[L1_coeffs 0] - [0 0 L0coeffs] )/2 CourseNana.COM

You should be able to spot a pattern forming that corresponds to Bonnet's recursion formula. Obviously you will need to use a loop and work out how to increment the number of coefficients for each iteration. You can check your polynomials against the symbolic math toolbox function legendreP. CourseNana.COM

Part 2: Your Solution CourseNana.COM

% Enter your code here and your local functions at the bottom. CourseNana.COM

Enter explanation here. CourseNana.COM

Part 3: Function Roots [8 marks] CourseNana.COM

Compare the various root finding methods that are amenable to this function, without knowing its derivative, to find all roots on the interval. Compare with sine and cosine. Compare with fzero. CourseNana.COM

Investigate the different methods of root finding covered in the course to find all of the roots on the interval for the zeroth order Bessel function of the first kind, , as follows: CourseNana.COM

·       M3.1: Write a local MATLAB function called fzeroJ that uses the built-in MATLAB function fzero. [1] CourseNana.COM

·       M3.2: Write a local MATLAB function called bisectionJ that uses the bisection method. [1] CourseNana.COM

·       M3.3: Write a local MATLAB function called newtonJ that uses Newton's method. [1] CourseNana.COM

·       M3.4: Write a local MATLAB function called secantJ that uses the Secant method. [1] CourseNana.COM

All functions should: CourseNana.COM

·       take as input the order of the Bessel function and the start and end points of the interval (i.e. [0 10]). CourseNana.COM

·       output the roots to a tolerance of 1e-6 (in other words stop iterating when the solution is changing by less than the tolerance), if this is possible within a computation time of say 10 minutes (use Ctrl+C or Command+. to stop the computation if not). CourseNana.COM

·       NOT use predetermined search intervals, but rather determine these from the function itself (so that in principle your code would function for any order/kind of Bessel function and/or outside the interval). CourseNana.COM

·       all use the same method for determining the search interval. CourseNana.COM

You should evaluate the performance of your local functions as follows: [1] CourseNana.COM

·       E3.1: Plot the approximated roots alongside the function evaluated using besselj, using a different plot for each method. CourseNana.COM

·       E3.2: Compute and output the time required to compute all roots on the interval using e.g. sprintf (as in the Computer Lab Codes) to clearly state which values relate to which method. CourseNana.COM

Questions CourseNana.COM

·       Q3.1: How do the various methods compare in terms of accuracy and computation time? [1] CourseNana.COM

·       Q3.2: Are your roots to within machine precision of the true values on page 409 of Abramowitz and Stegun? If not, why not? [1] CourseNana.COM

·       Q3.3: Does your function work for other orders of the Bessel function of the first kind, , and/or for roots outside the interval (i.e. )? If so, when does it stop working and why? How would you need to modify your code to get it to work? N.B. you should not try to modify your function to get it to work on other functions or outside the interval, as this problem is hard enough already, but you should only try to understand (and explain) why it doesn't work. [1] CourseNana.COM

Hints CourseNana.COM

One way to find the search interval is to start from the origin and find the first data point where the sign has changed, then search between that point and the next. You can then continue this to the next root. CourseNana.COM

Method 3.3: You will need to work out the derivative. This can be found from the series definition of the function, and you can also look it up at DLMF: §10.6 Recurrence Relations and Derivatives Bessel and Hankel Functions Chapter 10 Bessel Functions (nist.gov). CourseNana.COM

Part 3: Your Solution CourseNana.COM

% Enter your code here and your local functions at the bottom. CourseNana.COM

Enter explanation here. CourseNana.COM

Your Functions CourseNana.COM

Part 1: CourseNana.COM

% Local functions for part 1. CourseNana.COM

Part 2: CourseNana.COM

% Local functions for part 2. CourseNana.COM

Part 3: CourseNana.COM

% Local functions for part 3. CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Bessel functions代写,Matlab代写,Computing and Numerical Methods 1代写,Numerical Methods代写,Bessel functions代编,Matlab代编,Computing and Numerical Methods 1代编,Numerical Methods代编,Bessel functions代考,Matlab代考,Computing and Numerical Methods 1代考,Numerical Methods代考,Bessel functionshelp,Matlabhelp,Computing and Numerical Methods 1help,Numerical Methodshelp,Bessel functions作业代写,Matlab作业代写,Computing and Numerical Methods 1作业代写,Numerical Methods作业代写,Bessel functions编程代写,Matlab编程代写,Computing and Numerical Methods 1编程代写,Numerical Methods编程代写,Bessel functionsprogramming help,Matlabprogramming help,Computing and Numerical Methods 1programming help,Numerical Methodsprogramming help,Bessel functionsassignment help,Matlabassignment help,Computing and Numerical Methods 1assignment help,Numerical Methodsassignment help,Bessel functionssolution,Matlabsolution,Computing and Numerical Methods 1solution,Numerical Methodssolution,