/***************** NUMERICAL DIFFERENTION *********************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
float funct(float a);
int main()
{
char choice='y';
float f1,f2,x,h;
clrscr();
cout<<"X ? ";cin>>x;
do{
cout<<"Enter value of h ? ";cin>>h;
cout<<endl<<"The derivative is: "<<endl;
f1=(funct(x+h)-funct(x))/h;
f2=(funct(x+h)-funct(x-h))/(2*h);
cout<<"2 point derivative : "<<f1;
cout<<endl<<"3 points derivative: "<<f2;
cout<<endl<<"wanna continue (y/n) ? ";cin>>choice;
}while(choice=='y');
getch();
return 0;
}
float funct(float x)
{
return exp(x)*sin(x);
}
C C++ code- numerical differentiation of given equation
Subscribe to:
Post Comments
(
Atom
)
f2 is f1 after derivation?
ReplyDelete