You are on page 1of 1

#include <stdio.

h>
#include <conio.h>
#include <math.h>
double fx(double x);
double derivative(double h, double y[]);
void main()
{
double x[5], y[5], val_x, h;
printf("Enter value x and step size h : ");
scanf("%lf%lf", &val_x, &h);
for (int i=0; i<5; i++)
{
x[i]=val_x+(i-2)*h;
y[i]=fx(x[i]);
}
printf("Result: f'(%.2lf) = %lf", val_x, derivative(h,y));
getch();
}
double fx(double x)
{
return 5*exp(-2*x)*x;
}
double derivative(double h, double y[])
{
int i=2;
return (-y[i+2]+8*y[i+1]-8*y[i-1]+y[i-2])/(12*h); //centered difference
}

You might also like