解法一:∵xy''-y'=x²e^x ==>(xy''-y')/x²=e^x
==>(y'/x)'=e^x
==>y'/x=e^x+2C1 (C1是积分常数)
==>y'=xe^x+2C1x
==>y=xe^x-e^x+C1x²+C2 (C2是积分常数)
∴原方程的通解是y=xe^x-e^x+C1x²+C2 (C1,C2是积分常数).
解法二:∵令y'=p,则y''=p'
∴代入原方程,得xp'-p=x²e^x.(1)
显然,齐次方程xp'-p=0的通解是p=Cx (C是积分常数)
于是,根据常数变易法,设方程(1)的解为p=C(x)x (C(x)是关于x的函数)
∵代入方程(1),得x[C'(x)x-C(x)]-C(x)x=x²e^x
==>C'(x)=e^x
==>C(x)=e^x+2C1 (C1是积分常数)
==>p=xe^x+2C1x
则方程(1)的通解是p=xe^x+2C1x (C1是积分常数)
∴y'=xe^x+2C1x ==>y=xe^x-e^x+C1x²+C2 (C2是积分常数)
故原方程的通解是y=xe^x-e^x+C1x²+C2 (C1,C2是积分常数).