/************************************************************** * Analyze a real function F(x) by giving its equation * * ----------------------------------------------------------- * * Ref.: Analyse numérique en C By Alain Reverchon and * * Marc Ducamp, Armand Colin Editor, Paris, 1990" * * [BIBLI 14]. * * ----------------------------------------------------------- * * SAMPLE RUN: * * * * * * Analyze a real function F(x) by giving its equation * * * * Enter equation of Function f(x): sin(x)/x * * * * Begin x: 0.1 * * * * End x : 1 * * * * Number of points: 10 * * * * Caption: SIN(X)/X * * * * * * SIN(X)/X * * * * x= 0.100000000000 y= 0.998334166468 # 1798/1801 * * x= 0.200000000000 y= 0.993346653975 # 1493/1503 * * x= 0.300000000000 y= 0.985067355538 # 2045/2076 * * x= 0.400000000000 y= 0.973545855772 # 5741/5897 * * x= 0.500000000000 y= 0.958851077200 # 4707/4909 * * x= 0.600000000000 y= 0.941070788992 # 2619/2783 * * x= 0.700000000000 y= 0.920310981768 # 947/1029 * * x= 0.800000000000 y= 0.896695113624 # 4097/4569 * * x= 0.900000000000 y= 0.870363232919 # 2276/2615 * * x= 1.000000000000 y= 0.841470984808 # 2723/3236 * * * * (In this version, we only display the calculated couples * * [xi,yi]). See API demo program grfunct1.cpp to have a * * graph of the analyzed function. * * * * C++ version by J-P Moreau, Paris. * * (www.jpmoreau.fr) * * ----------------------------------------------------------- * * Note: this program demonstrates the capability of the module* * Fonction.cpp to compile a user defined real function * * F(x), given by its equation, and to evaluate a current* * point. * * * * Accepted signs and operators: * * ---------------------------- * * 0,1,2,3,4,5,6,7,8,9,(,),-,+,*,/,^,SIN,COS,TAN,ARCSIN,ARCCOS,* * ARCTAN,SH,CH,TH,ARGSH,ARGCH,ARGTH,ABS,INT,FRAC,FACT,EXP,LN, * * SQR (^ for power, SQRT for square root). * *************************************************************** uses functions ar_anal_fonction, ar_eval_f of fonction.cpp, ar_aff_reel, ar_aff_reel_ln of armath.cpp. here no use is made of optional type ar_nombre. -------------------------------------------------------------*/ #include "armath.h" char text[100]; //formula of function to analyze int n,ndata; //ndata: number of points to evaluate double dx,x,x1,x2; //x increment,current x, x begin, x end char sx[20]; //auxiliary string char title[40]; //caption of function f(x) void main() { extern char *f_ana; // Analyzed formula printf("\n Analyze a real function F(x) defined by its equation\n"); printf("\n Enter equation of Function f(x): "); scanf("%s", text); //see file Fonction.cpp ar_anal_fonction (text, (ar_fonction *) &ar_glob_f); //if compile of text is a success: printf("\n Begin x: "); scanf("%lf", &x1); printf("\n End x : "); scanf("%lf", &x2); printf("\n Number of points: "); scanf("%d", &ndata); printf("\n Caption: "); scanf("%s", title); printf("\n\n"); //Put ndata ordinates of F(x) in table Y printf(" %s\n\n", title); dx=(x2-x1)/(ndata-1); x=x1-dx; for (n=0; n