# include # include using namespace std; # include "runge.hpp" //****************************************************************************80 double runge_antideriv ( double x ) //****************************************************************************80 // // Purpose: // // runge_antideriv() evaluates the antiderivative of the Runge function. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 March 2025 // // Author: // // John Burkardt // // Input: // // double x: the argument of the function. // // Output: // // double runge_antideriv: the value of the antiderivative. // { double value; value = atan ( 5.0 * x ) / 5.0; return value; } //****************************************************************************80 double runge_deriv ( double x ) //****************************************************************************80 // // Purpose: // // runge_deriv() evaluates the derivative of the Runge function. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 March 2025 // // Author: // // John Burkardt // // Input: // // double x: the argument of the function. // // Output: // // double runge_deriv: the value of the derivative. // { double value; value = - 50.0 * x / pow ( 1.0 + 25.0 * x * x, 2 ); return value; } //****************************************************************************80 double runge_deriv2 ( double x ) //****************************************************************************80 // // Purpose: // // runge_deriv2() evaluates the second derivative of the Runge function. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 March 2025 // // Author: // // John Burkardt // // Input: // // double x: the argument of the function. // // Output: // // double runge_deriv2, the value of the second derivative. // { double u; double up; double v; double value; double vp; u = - 50.0 * x; up = - 50.0; v = pow ( 1.0 + 25.0 * x * x, 2 ); vp = 2.0 * ( 1.0 + 25.0 * x * x ) * ( 50.0 * x ); value = ( up * v - u * vp ) / pow ( v, 2 ); return value; } //****************************************************************************80 double runge_fun ( double x ) //****************************************************************************80 // // Purpose: // // runge_fun() evaluates the Runge function. // // Discussion: // // This function causes a breakdown for // polynomial interpolation over equally spaced nodes in [-1,+1]. // // Runge originally considered the function 1/(1+x^2) over the // interval [-5,+5]. For convenience, a rescaled version is considered // over the interval [-1,+1]. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 March 2025 // // Author: // // John Burkardt // // Input: // // double x: the argument of the function. // // Output: // // double runge_fun: the value of the function. // { double value; value = 1.0 / ( 1.0 + 25.0 * x * x ); return value; } //****************************************************************************80 double runge_power_series ( double x, int n ) //****************************************************************************80 // // Purpose: // // runge_power_series() evaluates a power series for the Runge function. // // Discussion: // // The Runge function considered here has the form // f(x) = 1 / ( 1 + 25x^2 ) // // The power series is 1 - (5x)^2 + (5x)^4 - (5x)^6 + (5x)^8 - (5x)^10 ... // // The power series is only well defined in the open interval // -1/5 < x < 1/5 // where successive terms gradually go to zero. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 25 March 2025 // // Author: // // John Burkardt // // Input: // // real x: the argument of the function. // // integer n: the number of terms to be computed. // // Output: // // real value: the value of the function. // { int i; double term; double value; value = 0.0; term = 1.0; for ( i = 1; i <= n; i++ ) { value = value + term; term = - term * pow ( 5.0 * x, 2 ); } return value; }