nonlin_newton


nonlin_newton, a MATLAB code which interactively applies Newton's method to seek a root of a function given formulas for f(x), f'(x), and a starting value a.

The user enters formulas for f(x), f'(x), and the value a.

The program then repeatedly applies Newton's method until it encounters a very small function value or it detects a problem with the iteration.

The program can be invoked by a function call, in which case the strings specifying f(x) and f'(x) must be quoted:

        [ a, fa, it ] = nonlin_newton ( 'cos(x)-x', '-sin(x)-1', 0 )
      
or as an interactive command with arguments:
        [ a, fa, it ] = nonlin_newton cos(x)-x -sin(x)-1 0
      
or, if called with no arguments, it will request them:
        [ a, fa, it ] = nonlin_newton ( );
        Enter function formula, like x^2: cos(x)-x
        Enter derivative formula, like 2*x: -sin(x)-1
        Enter starting point, a: 0
      

The function is specified as a string which is either:

The string should not contain any spaces between symbols, except when it is passed as a function argument in quotes.

It is not necessary to use the "dot" notation for expressions involving '*', '/', or '^', but it doesn't hurt either.

Examples of function specifications:

        x^2
        x.^2
        3/(x^4+5*x-6)
        sin(7*x)*sqrt(x)/8
        wiggle(x)     <-- where "wiggle.m" is a user-provided M file.
      

Licensing:

The computer code and data files made available on this web page are distributed under the MIT license

Languages:

nonlin_newton is available in a MATLAB version.

Related Data and Programs:

nonlin_newton_test

approx_bernstein, a MATLAB code which interactively approximates a function f(x) in the interval [a,b] by constructing a Bernstein polynomial.

approx_chebyshev, a MATLAB code which interactively approximates a function f(x) in the interval [a,b] by constructing a Chebyshev polynomial interpolant that is often a good estimate of the minmax polynomial.

approx_leastsquares, a MATLAB code which interactively approximates a function f(x) in the interval [a,b] by constructing an m-degree polynomial which minimizes the square root of the sum of the squares of the error with n sample data points.

diff_center, a MATLAB code which interactively uses centered differences to estimate the derivative of a function f(x), using a stepsize h.

diff_forward, a MATLAB code which interactively uses forward differences to estimate the derivative of a function f(x), using a stepsize h.

diff2_center, a MATLAB code which interactively uses centered differences to estimate the second derivative of a function f(x), using a stepsize h.

dot_l2, a MATLAB code which estimates the L2 dot product of two functions over an interval [A,B], with the functions entered as a string.

interp_chebyshev, a MATLAB code which interactively uses n Chebyshev spaced nodes in the interval [a,b] to interpolate a function f(x) with a polynomial.

interp_equal, a MATLAB code which interactively uses n equally spaced nodes in the interval [a,b] to interpolate a function f(x) with a polytnomial.

interp_ncs, a MATLAB code which interactively constructs a natural cubic spline (NCS) interpolant to a function f(x), using the 'zero second derivative' end condition.

interp_spline, a MATLAB code which interactively constructs a cubic spline interpolant to (x,y) data.

iplot, a MATLAB code which interactively plots a function f(x) over a domain a ≤ x ≤ b;

nonlin_bisect, a MATLAB code which interactively uses bisection to seek a zero of a function f(x) within a domain a ≤ x ≤ b;

nonlin_fixed_point, a MATLAB code which interactively uses fixed point iteration x=g(x) to seek a zero of a function f(x) given a starting point x0 and a number of iterations it;

nonlin_regula, a MATLAB code which interactively uses the regula falsi method to seek a zero of a function f(x) within a domain a ≤ x ≤ b;

nonlin_secant, a MATLAB code which interactively uses the secant method to seek a zero of a function f(x) given two starting estimates a and b.

nonlin_snyder, a MATLAB code which interactively uses Snyder's variation of the regula falsi method to seek a zero of a function f(x) within a change of sign interval [a,b];

norm_l1, a MATLAB code which estimates the L1 norm of a function over an interval [A,B], with the function entered as a string.

norm_l2, a MATLAB code which estimates the L2 norm of a function over an interval [A,B], with the function entered as a string.

norm_loo, a MATLAB code which estimates the L-infinity norm of a function over an interval [A,B], with the function entered as a string.

norm_rms, a MATLAB code which estimates the root mean square (RMS) norm of a function over an interval [A,B], with the function entered as a string.

ode_euler, a MATLAB code which interactively applies the Euler method to estimate the solution of an ordinary differential equation (ODE) y'=f(x,y), over the interval [a,b], with initial condition y(a)=ya, using n steps.

ode_euler_backward, a MATLAB code which interactively applies the backward Euler method to estimate the solution of an ordinary differential equation (ODE) y'=f(x,y), over the interval [a,b], with initial condition y(a)=ya, using n steps.

ode_euler_system, a MATLAB code which interactively applies the Euler method to estimate the solution of a system of ordinary differential equations (ODE) y'=f(x,y), over the interval [a,b], with initial condition y(a)=ya, using n steps.

ode_midpoint, a MATLAB code which interactively applies the midpoint method to estimate the solution of an ordinary differential equation (ODE) y'=f(x,y), over the interval [a,b], with initial condition y(a)=ya, using n steps.

ode_midpoint_system, a MATLAB code which interactively applies the midpoint method to estimate the solution of a system of ordinary differential equations (ODE) y'=f(x,y), over the interval [a,b], with initial condition y(a)=ya, using n steps.

ode_rk4, a MATLAB code which interactively applies a fourth order Runge-Kutta method to estimate the solution of an ordinary differential equation (ODE) y'=f(x,y), over the interval [a,b], with initial condition y(a)=ya, using n steps.

ode_trapezoidal, a MATLAB code which interactively applies the trapezoidal method to estimate the solution of an ordinary differential equation (ODE) y'=f(x,y), over the interval [a,b], with initial condition y(a)=ya, using n steps.

opt_golden, a MATLAB code which interactively estimates a minimizer of a function f(x) over the interval [a,b], assuming f(x) is unimodular (U-shaped) over the interval [a,b].

opt_gradient_descent, a MATLAB code which interactively seeks a local minimum of a function f(x), given a formula for the derivative f'(x), a starting point x0, and a stepsize factor gamma.

opt_quadratic, a MATLAB code which interactively uses quadratic interpolation to estimate a critical point of a function f(x) given three starting points, an iteration limit n, and tolerances for x and y.

opt_sample, a MATLAB code which interactively estimates the minimum and maximum of a function f(x) over an interval [a,b], using n random sample values, with the function entered as a string.

quad_gauss, a MATLAB code which interactively uses an n-point Gauss quadrature rule to estimate the integral of a function f(x) in the interval [a,b].

quad_monte_carlo, a MATLAB code which interactively uses n random samples to estimate the integral of a function f(x) in the interval [a,b].

quad_trap, a MATLAB code which interactively applies a trapezoidal quadrature rule using n intervals to estimate the integral of a function f(x) over an interval [a,b].

Source Code:


Last revised on 07 July 2019.