Or login with:
| doubletaylor1( | double | (*f)(double)[function pointer] | |
| double | x | ||
| double | h | ||
| double | gamma = 1.0 | )[inline] |
#include <codecogs/maths/calculus/diff/taylor.h> #include <stdio.h> #include <math.h> // precision constant #define H 0.001 // function to differentiate double f(double x) { return cos(x); } // the derivative of the function, to estimate errors double df(double x) { return -sin(x); } int main() { // display precision printf(" h = %.3lf\n\n", H); // compute the numerical derivative double fh = Maths::Calculus::Diff::taylor1(f, 1, H); // display the result and error estimate printf(" f(x) = cos(x)\n"); printf(" f`(1) = %.15lf\n", fh); printf("real value = %.15lf\n", df(1)); printf(" error = %.15lf\n\n", fabs(fh - df(1))); return 0; }Output
h = 0.001 f(x) = cos(x) f`(1) = -0.841470844562695 real value = -0.841470984807897 error = 0.000000140245202
| f | the function to differentiate |
| x | the abscissa at which you want to compute the first derivative |
| h | the value of the precision constant h |
| gamma | Default value = 1.0 |
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
| doubletaylor2( | double | (*f)(double)[function pointer] | |
| double | x | ||
| double | h | ||
| double | gamma = 1.0 | )[inline] |
#include <codecogs/maths/calculus/diff/taylor.h> #include <stdio.h> #include <math.h> // precision constant #define H 0.0001 // function to differentiate double f(double x) { return cos(x); } // the second derivative of the function, to estimate errors double d2f(double x) { return -cos(x); } int main() { // display precision printf(" h = %.4lf\n\n", H); // compute the numerical derivative double fh = Maths::Calculus::Diff::taylor2(f, 1, H); // display the result and error estimate printf(" f(x) = cos(x)\n"); printf(" f``(1) = %.15lf\n", fh); printf("real value = %.15lf\n", d2f(1)); printf(" error = %.15lf\n\n", fabs(fh - d2f(1))); return 0; }Output
h = 0.0001 f(x) = cos(x) f``(1) = -0.540302319866019 real value = -0.540302305868140 error = 0.000000013997879
| f | the function to differentiate |
| x | the abscissa at which you want to compute the second derivative |
| h | the value of the precision constant h |
| gamma | Default value = 1.0 |
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
You must login to leave a messge