Hi.
Try this. (This is the first time I've used "inline" with a
vector-valued function.)
F = inline('-[8 5; 5 8]*x','t','x')
[t,x] = ode45(F,[0 2],[0; 1]);
[x1,x2] = dsolve('Dx1 = -8*x1-5*x2', 'Dx2 = -5*x1-8*x2', 'x1(0)=0', 'x2(0)=1')
exact = [subs(x1,t) subs(x2,t)];
plot(t,x-exact)
The idea is to have ode45 determine the values of t it likes and then
substitute those values into the analytic solution obtained with dsolve.
The graph shows that, with ode45's default tolerances, the maximum error
is about 3e-5.
Nice example. Thanks.
-- Cleve Moler
mo...@mathworks.com