function [ fx, fp ] = testzero ( x ) %TESTZERO evaluates one of several scalar nonlinear test functions. % % Form: % % function [ fx, fp ] = testzero ( x ) % % Discussion: % % To make use of this function while running MATLAB, you must issue % the command % global IPROB % and then set IPROB to a value between 1 and 8 to select a % particular problem. % % Example: % % global IPROB = 1 % % [ fx, fp ] = testzero ( x ) % % Modified: % % 15 November 1999 % % Author: % % John Burkardt % % Parameters: % % As discussed above, the global parameter IPROB must be set to % a value between 1 and 8 to choose a function. % % Input, X is the point at which the function should be evaluated; % % Output, FX is the value of the selected function at X. % Output, FP is the derivative of the function at X. % global IPROB if IPROB == 1 fx = sin ( x ) - 0.5 * x; fp = cos ( x ) - 0.5; elseif IPROB == 2 fx = 2.0 * x - exp ( - x ); fp = 2.0 + exp ( - x ); elseif IPROB == 3 fx = x * exp ( - x ); fp = exp ( - x ) * ( 1.0 - x ); elseif IPROB == 4 fx = exp ( x ) - 1.0 / ( 10.0 * x )^2; fp = exp ( x ) + 2.0 / ( 100.0 * x^3 ); elseif IPROB == 5 fx = ( x + 3.0 ) * ( x - 1.0 )^2; fp = ( 3.0 * x + 5.0 ) * ( x - 1.0 ); elseif IPROB == 6 fx = exp ( x ) - 2.0 - 1.0 / ( 10.0 * x )^2 + 2.0 / ( 100.0 * x )^3; fp = exp ( x ) + 2.0 / ( 100.0 * x^3 ) - 6.0 / ( 1000000.0 * x^4 ); elseif IPROB == 7 fx = x^3; fp = 3.0 * x^2; elseif IPROB == 8 fx = cos ( x ) - x; fp = - sin ( x ) - 1.0; else error ( 'TESTZERO - Fatal error; Value of IPROB was out of range.' ) end