1 /* Original version of this file copyright 1999 by Michael Wester,
2 * and retrieved from http://www.math.unm.edu/~wester/demos/Series/problems.macsyma
5 * Released under the terms of the GNU General Public License, version 2,
6 * per message dated 2007-06-03 from Michael Wester to Robert Dodier
7 * (contained in the file wester-gpl-permission-message.txt).
9 * See: "A Critique of the Mathematical Abilities of CA Systems"
10 * by Michael Wester, pp 25--60 in
11 * "Computer Algebra Systems: A Practical Guide", edited by Michael J. Wester
12 * and published by John Wiley and Sons, Chichester, United Kingdom, 1999.
14 /* ----------[ M a c s y m a ]---------- */
15 /* ---------- Initialization ---------- */
18 /* ---------- Series ---------- */
19 /* Taylor series---this first example comes from special relativity
20 => 1 + 1/2 (v/c)^2 + 3/8 (v/c)^4 + 5/16 (v/c)^6 + O((v/c)^8) */
24 /* Note: sin(x) = x - x^3/6 + x^5/120 - x^7/5040 + O(x^9)
25 cos(x) = 1 - x^2/2 + x^4/24 - x^6/720 + O(x^8)
26 tan(x) = x + x^3/3 + 2/15 x^5 + 17/315 x^7 + O(x^9) */
27 tsin: taylor(sin(x), x, 0, 7);
28 tcos: taylor(cos(x), x, 0, 7);
29 /* Note that additional terms will be computed as needed */
31 taylor(tan(x), x, 0, 7);
33 /* => -x^2/6 - x^4/180 - x^6/2835 - O(x^8) */
34 taylor(log(sin(x)/x), x, 0, 7);
35 taylor(sin(x)/x, x, 0, 7);
36 taylor(log(%), x, 0, 7);
37 /* => [a f'(a d) + g(b d) + integrate(h(c y), y = 0..d)]
38 + [a^2 f''(a d) + b g'(b d) + h(c d)] (x - d) */
39 diff(f(a*x), x) + g(b*x) + integrate(h(c*y), y, 0, x);
42 /* Taylor series of nonscalar objects (noncommutative multiplication)
43 => (B A - A B) t^2/2 + O(t^3) [Stanly Steinberg] */
44 declare([A, B], nonscalar)$
45 %e^((A + B)*t) - %e^(A*t) * %e^(B*t);
47 taylor(%e^((A + B)*t) - %e^(A*t) * %e^(B*t), t, 0, 4);
48 remove([A, B], nonscalar)$
50 => sum( Bernoulli[k]/k! x^(k - 2), k = 1..infinity )
51 = 1/x^2 - 1/(2 x) + 1/12 - x^2/720 + x^4/30240 + O(x^6)
52 [Levinson and Redheffer, p. 173] */
53 taylor(1/(x*(exp(x) - 1)), x, 0, 7);
54 /* Puiseux series (terms with fractional degree):
55 => 1/sqrt(x - 3/2 pi) + (x - 3/2 pi)^(3/2) / 12 + O([x - 3/2 pi]^(7/2)) */
56 taylor(sqrt(sec(x)), x, 3/2*%pi, 4);
57 /* Generalized Taylor series => sum( [x log x]^k/k!, k = 0..infinity ) */
59 /* Compare the generalized Taylor series of two different formulations of a
60 function => log(z) + log(cosh(w)) + tanh(w) z + O(z^2) */
61 s1: taylor(log(sinh(z)) + log(cosh(z + w)), z, 0, 1);
62 s2: taylor(log(sinh(z) * cosh(z + w)), z, 0, 1);
65 /* Look at the generalized Taylor series around x = 1
66 => (x - 1)^a/e^b [1 - (a + 2 b) (x - 1) / 2 + O((x - 1)^2)] */
69 /* Asymptotic expansions => sqrt(2) x + O(1/x) */
70 taylor(sqrt(2*x^2 + 1), x, inf, 0);
71 /* Wallis' product => 1/sqrt(pi n) + ... [Knopp, p. 385] */
72 errcatch(taylor(1/2^(2*n) * binomial(2*n, n), n, inf, 0));
73 /* => 0!/x - 1!/x^2 + 2!/x^3 - 3!/x^4 + O(1/x^5) [Knopp, p. 544] */
74 exp(x) * 'integrate(exp(-t)/t, t, x, inf);
75 errcatch(taylor(%, x, inf, 5));
76 /* Multivariate Taylor series expansion => 1 - (x^2 + 2 x y + y^2)/2 + O(x^4)
78 taylor(cos(x + y), [x, y], 0, 3);
79 taylor(cos(x + y), [x, 0, 3], [y, 0, 3]);
81 /* Power series (compute the general formula) */
83 powerseries(log(sin(x)/x), x, 0);
85 powerseries(exp(-x)*sin(x), x, 0);
87 /* Derive an explicit Taylor series solution of y as a function of x from the
88 following implicit relation:
89 y = x - 1 + (x - 1)^2/2 + 2/3 (x - 1)^3 + (x - 1)^4 + 17/10 (x - 1)^5 + ...
92 taylor_revert(%, y, 7);
93 /* Pade (rational function) approximation => (2 - x)/(2 + x) */
94 pade(taylor(exp(-x), x, 0, 2), 1, 1);
95 /* Fourier series of f(x) of period 2 p over the interval [-p, p]
96 => - (2 p / pi) sum( (-1)^n sin(n pi x / p) / n, n = 1..infinity ) */
98 fourier_series(x, x, p);
100 - (2 p / pi^2) sum( [1 - (-1)^n] cos(n pi x / p) / n^2, n = 1..infinity ) */
101 fourier_series(abs(x), x, p);