1/* Filename <name>.mac
2
3   ***************************************************************
4   *							         *
5   *                     <package name>                          *
6   *                <functionality description>                  *
7   *                                                             *
8   *          from: Computer Algebra in Applied Math.            *
9   *                   by Rand (Pitman,1984)                     *
10   *                Programmed by Richard Rand                   *
11   *      These files are released to the public domain          *
12   *            						 *
13   ***************************************************************
14(d4) This program generates the Taylor series solution
15
16
17to the Nth order ODE:
18
19
20            (N)                             (N-1)
21
22
23	   Y    =  F ( X, Y, Y', Y'', ..., Y      )
24
25
26for arbitrary initial conditions at X = 0.
27
28
29To call it, type:
30
31
32                   SOLUTION()
33
34*/
35
36
37solution():=(input(),step1(),step2(),v:f,
38	 for i from n thru m do (u:u+evaluate(v)*x^i/i!,v:deriv(v)),output())$
39input():=(n:read("ENTER ORDER OF D.E."),m:read("ENTER DEGREE OF TRUNCATION"),
40      f:read("ENTER RIGHT HAND SIDE OF ODE.\
41REPRESENT Y BY Y[0], Y' BY Y[1], ETC."),
42      print(" "),print(f),print(" "),
43      for i from 0 thru n-1 do z[i]:read("ENTER INITIAL VALUE OF Y[",i,"]"))$
44step1():=u:sum(z[i]*x^i/i!,i,0,n-1)$
45step2():=initial:makelist([y[i] = z[i]],i,0,n-1)$
46deriv(g):=diff(g,x)+sum(diff(g,y[i])*y[i+1],i,0,n-2)+diff(g,y[n-1])*f$
47evaluate(g):=ev(g,x:0,initial)$
48output():=print("Y =",u)$
49