-
Notifications
You must be signed in to change notification settings - Fork 0
/
newtonconvergence.m
28 lines (28 loc) · 1002 Bytes
/
newtonconvergence.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [xsol,nsol] = newtonconvergence(df,d2f,x0,tol,xex)
% FUNCTION to compute rates of convergence, number of iterations, and
% final error for newtons method
%
% INPUTS:
% df - gradient of f
% d2f - hessian of f
% x0 - starting value of x
% tol - ubser defined tolerance
% xex - exact solution
%
% OUTPUTS:
% xsol - computed solution x_n using newtons method
% nsol - number of iterations x_0,...,x_n
%
%
% compute newtons method for starting value x0.
[xsol,nsol] = newton(df,d2f,x0,tol);
%display number of iterations
disp(['Number of iterations: ', num2str(nsol)]);
% make testing convergence tables
disp(['Table for Newtons method for x0 =[',num2str(transpose(x0)),']^T'])
disp(['Table designed to show potential candidate convergence rates'])
[output,e] = makeconvergencetable(xex,xsol,nsol);
disp(output)
% displays final error
disp(['Final error: ', num2str(e(nsol+1))]);
end