/******************************************************** * Calculate a limited development of a real function * * f(x)*g(x) at x=0 up at order 25, knowing the limited * * developments of f(x) and g(x). * * ----------------------------------------------------- * * SAMPLE RUN: * * * * Limited development of a real function f(x)*g(x): * * * * Function to develop: exp(x)*(1/1+x) * * * * Limited development of f(x)=exp(x) is: * * 1 + x + x^2/2! + x^3/3! + ... + x^n/n! + ... * * * * Limited development of g(x)=1/(1+x) is: * * 1 -x + x^2 + ... + (-1)^n*x^n + ... * * * * Order of development (max=25): 5 * * * * Input coefficients of limited dev. of f(x): * * a0 = 1 * * a1 = 1 * * a2 = 0.5 * * a3 = 0.1666667 * * a4 = 0.0416667 * * a5 = 0.0083333 * * * * Input coefficients of limited dev. of g(x): * * b0 = 1 * * b1 = -1 * * b2 = 1 * * b3 = -1 * * b4 = 1 * * b5 = -1 * * * * The coefficients of limited dev. of f(x)*g(x) are: * * c0 = 1.0000000 * * c1 = 0.0000000 * * c2 = 0.5000000 * * c3 = -0.3333333 * * c4 = 0.3750000 * * c5 = -0.3666667 * * * * ----------------------------------------------------- * * Ref.: "Mathematiques en Turbo Pascal By Alain * * Reverchon and Marc Ducamp, Editions Eyrolles, * * Paris, 1991" [BIBLI 03]. * * * * C++ version by J-P Moreau. * * (www.jpmoreau.fr) * ********************************************************/ #include #include #define SIZE 25 int i,m; double T1[SIZE+1],T2[SIZE+1],R[SIZE+1]; void ar_dlmult(int n, double *t1, double *t2, double *res) { int i,j; double x; if (n > SIZE) return; for (i=0; i<=n; i++) { x=0; for (j=0; j<=i; j++) x += t1[j]*t2[i-j]; res[i]=x; } } void main() { printf("\n Limited development of a real function f(x)*g(x):\n\n"); printf(" Function to develop: exp(x)*(1/1+x)\n\n"); printf(" Limited development of f(x)=exp(x) is:\n"); printf(" 1 + x + x^2/2! + x^3/3! + ... + x^n/n! + ...\n\n"); printf(" Limited development of g(x)=1/(1+x) is:\n"); printf(" 1 -x + x^2 + ... + (-1)^n*x^n + ...\n\n"); printf(" Order of development (max=25): "); scanf("%d", &m); printf("\n Input coefficients of limited dev. of f(x):\n"); for (i=0; i<=m; i++) { printf(" a%d = ",i); scanf("%lf",&T1[i]); } printf("\n Input coefficients of limited dev. of g(x):\n"); for (i=0; i<=m; i++) { printf(" b%d = ",i); scanf("%lf",&T2[i]); } printf("\n"); ar_dlmult(m,T1,T2,R); printf(" The coefficients of limited dev. of f(x)*g(x) are:\n"); for (i=0; i<=m; i++) printf(" c%d = %10.7f\n", i, R[i]); printf("\n\n"); } // end of file ltddev1.cpp