ELEC1703-matlab代写
时间:2022-12-01
ELEC1703
MATLAB Assignment
2 – report –
Student ID number
UNIVERSITY OF LEEDS
PETER PETERSON
2019
Peter Peterson
Student ID number
Contents
1. Root finding algorithms – Bisection method.......................................................................................5
1.1 Bisection function (original)...............................................................................................................5
Function code......................................................................................................................................5
Function f(x) plot.................................................................................................................................5
Testing initial bisection function with fx=x 4−2 x−2 with 5 iterations...........................................5
Testing effects of interval width and number of iterations.................................................................5
Comment.............................................................................................................................................5
1.2 Modified bisection function...............................................................................................................6
Modified function code.......................................................................................................................6
Code comments...................................................................................................................................6
Main code............................................................................................................................................6
Test the function for tolerance = 10−6..............................................................................................6
Plot of number of iterations vs tolerance with modified bisection function.......................................6
Plot of number of iterations vs tolerance with false position function................................................6
Comment.............................................................................................................................................6
2. Root finding algorithms – Newton method.........................................................................................7
2.1 Testing roots built-in function............................................................................................................7
Code....................................................................................................................................................7
Plot of f(x)............................................................................................................................................7
Comment.............................................................................................................................................7
2.2 Testing fzero built-in function............................................................................................................8
Code....................................................................................................................................................8
Test 1: Finding roots of f 1 x=x 4−2x−2.........................................................................................8
Test 2: Finding roots of f 2 x=x 4−2 x2+x.......................................................................................8
Comment.............................................................................................................................................8
2.3 Newton method – finding all zeroes automatically...........................................................................9
mynewtontol function code................................................................................................................9
Main code for filtration approach........................................................................................................9
Plot of fx=x 4−2 x−2.......................................................................................................................9
Snapshot of roots array before and after filtration..............................................................................9
1
Peter Peterson
Student ID number
Main code for incremental search algorithm......................................................................................9
Comment...........................................................................................................................................10
Snapshot of roots with incremental search.......................................................................................10
Plot of fx=x 2−2 x+1......................................................................................................................10
Snapshot of roots array with filtration and incremental search approach........................................10
Comment...........................................................................................................................................10
Incremental search hazards...............................................................................................................10
2.4 Newton method – effect of x...........................................................................................................11
Main code..........................................................................................................................................11
Plot of number of iterations vs x0 for fx=x 4−2 x−2.....................................................................11
Comment...........................................................................................................................................11
Plot of f(x)/f’(x)..................................................................................................................................11
Comment...........................................................................................................................................11
Plot of number of iterations vs x0 fx=x 2−2 x+1............................................................................12
Comment...........................................................................................................................................12
2.5 Newton method – effect of number of iterations............................................................................12
Main code..........................................................................................................................................12
Plot of number of iterations vs tolerance via Newton and bisection method...................................12
Comment...........................................................................................................................................12
3. Function fitting - linear and nonlinear regression..............................................................................13
3.1 Linear least-squares regression fitting.............................................................................................13
mylinregr.m function code................................................................................................................13
Main code..........................................................................................................................................13
Plot of fitted data...............................................................................................................................13
Comment...........................................................................................................................................13
3.2 Polynomial fitting.............................................................................................................................14
Main code..........................................................................................................................................14
Plot of fitted data...............................................................................................................................14
Comment...........................................................................................................................................14
4. Interpolation......................................................................................................................................15
4.1 Lagrange interpolation....................................................................................................................15
Lagrange interpolation function code................................................................................................15
Main code..........................................................................................................................................15
2
Peter Peterson
Student ID number
Population in 1945 – difference between Lagrange and linear fit.....................................................15
Plot of fitted data by Lagrange interpolation and linear fit................................................................15
Comment...........................................................................................................................................15
Population in 2015 by Lagrange method...........................................................................................16
Comment...........................................................................................................................................16
4.2 Inverse interpolation.......................................................................................................................16
a) 200 million.................................................................................................................................16
Code..................................................................................................................................................16
Plot of function for inverse interpolation..........................................................................................16
Year/s of 200 million population.......................................................................................................16
Comment...........................................................................................................................................16
b) Lagrange and quadratic regression comparison........................................................................17
Code..................................................................................................................................................17
Plot of function for inverse interpolation..........................................................................................17
Year/s when two fitting methods yield same result..........................................................................17
Comment...........................................................................................................................................17
5. Numerical integration........................................................................................................................18
5.1 Trapezoid integration......................................................................................................................18
Trap2 function code...........................................................................................................................18
Main code..........................................................................................................................................18
Plot of numerical error vs number of segments for the first function...............................................18
Plot of numerical error vs number of segments for the second function..........................................18
Comment...........................................................................................................................................18
5.2 Romberg integration........................................................................................................................19
Romberg function code.....................................................................................................................19
Main code..........................................................................................................................................19
Plot number of iterations vs tolerance for the first function.............................................................19
Plot number of iterations vs tolerance for the second function........................................................19
Comment...........................................................................................................................................19
3
Peter Peterson
Student ID number
Instructions:
- Insert your name and student number on cover page and document heading
- Most questions will require you to copy – paste what you did in MATLAB – you can do
this directly (copy-paste) or take a print screen (or use snipping tool in windows) and
paste a picture.
- Pasting snapshots via snipping tool in Windows is preferred. You may snapshot codes
as well.
- Comment your work. Your comments may carry 30 - 70% of the marks.
- Report format is guideline, feel free to change formatting style. Your main aim is to
create a neat summary of your work.
- When you are done, do not forget to update the table of contents on the first page. Right
click the table, click on Update Field, and choose Update entire table option.
4
Peter Peterson
Student ID number
1. Root finding algorithms – Bisection method
1.1 Bisection function (original)
Function code
(snapshot):
Function f(x) plot
(Make sure graph is properly labelled, and represented in neat manner)
Testing initial bisection function with f ( x )=x4−2 x−2 with 5 iterations
(snapshot of MATLAB Input/Output. Vary interval width and number of iterations
manually in order to derive their effect.):
Testing effects of interval width and number of iterations
(snapshot of MATLAB Input/Output. Vary interval width and number of iterations
manually in order to derive their effect.):
Comment
(Overall comment. Describe what you learned and what are the effects of the inputs of the
initial function. Check the original function code and explain what it does.)
5
Peter Peterson
Student ID number
1.2 Modified bisection function
Modified function code
(snapshot):
Code comments
(Describe how your code works and what you did, try commenting your lines within the code as
well.)
Main code
(snapshot):
Test the function for tolerance = 10−6
(snapshot of MATLAB output)
Plot of number of iterations vs tolerance with modified bisection function
(Make sure graph is properly labelled, and represented in neat manner)
Plot of number of iterations vs tolerance with false position function
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Overall comment. Describe what you learned and describe your observations on the graphs
by commenting the effects of tolerance variation and comparing two different functions)
6
Peter Peterson
Student ID number
2. Root finding algorithms – Newton method
2.1 Testing roots built-in function
Code
(snapshot – you can either write a script or use MATLAB command line directly):
Plot of f(x)
(Make sure graph us properly labelled, and represented in neat manner)
Comment
(Overall comment. Describe what you learned and describe how roots works)
7
Peter Peterson
Student ID number
2.2 Testing fzero built-in function
Code
(snapshot):
Test 1: Finding roots of f 1 ( x )=x4−2x−2
(snapshot)
Test 2: Finding roots of f 2 ( x )=x4−2x2+x
(snapshot)
Comment
(Overall comment. Describe what you learned and describe how fzero works)
8
Peter Peterson
Student ID number
2.3 Newton method – finding all zeroes automatically
mynewtontol function code
(snapshot)
Main code for filtration approach
(snapshot)
Plot of f ( x )=x4−2 x−2
(Make sure graph is properly labelled, and represented in neat manner)
Snapshot of roots array before and after filtration
Main code for incremental search algorithm
(snapshot)
9
Peter Peterson
Student ID number
Comment
(Comment on your observations)
Snapshot of roots with incremental search
Plot of f ( x )=x2−2x+1
(Make sure graph is properly labelled, and represented in neat manner)
Snapshot of roots array with filtration and incremental search approach
Comment
(Comment on your observations)
Incremental search hazards
10
Peter Peterson
Student ID number
Hazzard Example function
(Describe hazard) (Plot an example function that displays the hazard, make sure graph is properly labelled,
and represented in neat manner)
(Describe hazard) (Plot an example function that displays the hazard, make sure graph is properly labelled,
and represented in neat manner)
(Describe hazard) (Plot an example function that displays the hazard, make sure graph is properly labelled,
and represented in neat manner)
(Add/delete more rows to the table above if needed)
2.4 Newton method – effect of x
Main code
(snapshot)
Plot of number of iterations vs x0 for f ( x )=x4−2 x−2
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Comment on your observations)
Plot of f(x)/f’(x)
11
Peter Peterson
Student ID number
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Comment on your observations)
Plot of number of iterations vs x0 f ( x )=x2−2x+1
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Comment on your observations)
2.5 Newton method – effect of number of iterations
Main code
(snapshot)
Plot of number of iterations vs tolerance via Newton and bisection method
(Make sure graph is properly labelled, and represented in neat manner)
Comment
12
Peter Peterson
Student ID number
(Comment on your observations)
3. Function fitting - linear and nonlinear regression
3.1 Linear least-squares regression fitting
mylinregr.m function code
(snapshot)
Main code
(snapshot)
Plot of fitted data
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Overall comment. Describe what you learned and comment on your observations)
13
Peter Peterson
Student ID number
3.2 Polynomial fitting
Main code
(snapshot)
Plot of fitted data
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Overall comment. Describe what you learned and comment on your observations)
4. Interpolation
4.1 Lagrange interpolation
14
Peter Peterson
Student ID number
Lagrange interpolation function code
(snapshot)
Main code
(snapshot)
Population in 1945 – difference between Lagrange and linear fit
(snapshot)
Plot of fitted data by Lagrange interpolation and linear fit
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Comment on your observations)
Population in 2015 by Lagrange method
(snapshot)
Comment
15
Peter Peterson
Student ID number
(Overall comment. Describe what you learned and comment on your observations)
4.2 Inverse interpolation
a) 200 million
Code
(snapshot)
Plot of function for inverse interpolation
(Make sure graph is properly labelled, and represented in neat manner)
Year/s of 200 million population
(snapshot)
Comment
(Overall comment. Describe what you learned and comment on your observations)
b) Lagrange and quadratic regression comparison
Code
16
Peter Peterson
Student ID number
(snapshot)
Plot of function for inverse interpolation
(Make sure graph is properly labelled, and represented in neat manner)
Year/s when two fitting methods yield same result
(snapshot
Comment
(Overall comment. Describe what you learned and comment on your observations)
5. Numerical integration
17
Peter Peterson
Student ID number
5.1 Trapezoid integration
Trap2 function code
(snapshot)
Main code
(snapshot)
Plot of numerical error vs number of segments for the first function
(Make sure graph is properly labelled, and represented in neat manner)
Plot of numerical error vs number of segments for the second function
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Comment on your observations)
5.2 Romberg integration
Romberg function code
18
Peter Peterson
Student ID number
(snapshot)
Main code
(snapshot)
Plot number of iterations vs tolerance for the first function
(Make sure graph is properly labelled, and represented in neat manner)
Plot number of iterations vs tolerance for the second function
(Make sure graph is properly labelled, and represented in neat manner)
Comment
(Comment on your observations)
essay、essay代写