>> % Solution to Boyce-DiPrima problem 20, section 3.6 >> dsolve('D2y + y = t*(1 + sin(t))') ans = sin(t)*C2+cos(t)*C1+t+1/4*cos(t)+1/4*t*sin(t)-1/4*cos(t)*t^2 >> % solution by undetermined coefficients >> syms a b c d e f t >> y = t + a*sin(t) + b*cos(t) + c*t*sin(t) + d*t*cos(t) ... + e*t^2*sin(t) + f*t^2*cos(t); >> diff(y, t, 2) + y ans = 2*c*cos(t)-2*d*sin(t)+2*e*sin(t)+4*e*t*cos(t)+2*f*cos(t)-4*f*t*sin(t)+t >> collect(ans, sin(t)) ans = (-2*d-4*f*t+2*e)*sin(t)+2*c*cos(t)+t+4*e*t*cos(t)+2*f*cos(t) >> collect(ans, cos(t)) ans = (2*c+4*e*t+2*f)*cos(t)+(-2*d-4*f*t+2*e)*sin(t)+t >> % Thus e = 0, c+f = 0, e-d = 0, -4*f = 1. >> % a and b are arbitrary. >> [csol, dsol, esol, fsol] = solve(e, c+f, e-d, 1+4*f, c, d, e, f); >> [csol, dsol, esol, fsol] ans = [ 1/4, 0, 0, -1/4] >> subs(y, [c, d, e, f], [csol, dsol, esol, fsol]) ans = t+a*sin(t)+b*cos(t)+1/4*t*sin(t)-1/4*cos(t)*t^2 >> % check: >> diff(ans,t,2) + ans ans = t+t*sin(t)