Calculating forward error of a function in c -
i'd understand how calculate forward, , backward error of function using c double (64bit) type.
for example, how identify forward error of following function:
double func(double x){ return (pow(x,2.0)/cos(x)); } if relative error known = 10^-15.
i know forward error difference in value between exact answer f(x), , computed answer ^f(x). , backward error difference in value between value ^x, used compute ^f(x), , true value of x give calculated value ^f(x).
the problem have have no idea how calculate these errors in practice.
thank you.
sample forward difference using extended precision.
use volatile prevent double code using extended precision calculations.
#include <assert.h> #include <float.h> #include <math.h> long double func_test_forward(volatile double x) { #ifdef ldbl_dig assert(ldbl_dig > dbl_dig); #endif volatile double y = func(x); long double ly = powl(x, 2.0)/cosl(x); return y - ly; }
Comments
Post a Comment