--Copyright The Numerical Algorithms Group Limited 1994.
)cl all
-- There are 2 different ways to input a homogeneous 1st order system of
-- linear ordinary differential equations of the form  dy/dt = M y
-- where y is a vector of unknown functions of t.
-- the first is simply  solve(M, t)  which will be understood to be
-- a differential system:
M := matrix [[ 1+4*t,  -5*t,   7*t,  -8*t,   8*t,  -6*t],_
             [ -10*t, 1+9*t, -14*t,  16*t, -16*t,  12*t],_
             [  -5*t,   5*t, 1-8*t,   8*t,  -8*t,   6*t],_
             [  10*t, -10*t,  14*t,1-17*t,  16*t, -12*t],_
             [   5*t,  -5*t,   7*t,  -8*t, 1+7*t,  -6*t],_
             [  -5*t,   5*t,  -7*t,   8*t,  -8*t, 1+5*t]]
-- the original system in Barkatou's AAECC paper is t^2 dy/dt = M*y
sol := solve(inv(t**2) * M, t)
-- verify the solutions
[t**2 * map(h +-> D(h, t), v) - M * v for v in sol]
-- the second way is to type each equation using a separate operator for
-- each unknown:
x := operator x
y := operator y
sys := [D(x t, t) = x t + sqrt 3 * y t, D(y t, t) = sqrt 3 * x t - y t]
solve(sys, [x, y], t).basis
-- Similarly there are 2 different ways to input the inhomogeneous system
-- dy/dt = M y + v  where v is a given vector of functions.
-- the first is   solve(M, v, t):
v := vector [1, (-29*t + 19)/5, -1, t + 1, - 2*t + 3, -1]
-- get a particular solution to  t^2 dy/dt = M y + v
solp := solve(inv(t**2) * M, inv(t**2) * v, t).particular
-- verify the particular solution
t**2 * map(h +-> D(h, t), solp) - M * solp - v
-- the second way is by listing the equations:
z := operator z
sys := [D(x t, t) = y t + z t + t, D(y t, t) = x t + z t, D(z t, t) = x t + y t]
solve(sys, [x, y, z], t).particular
