# Thread: Matlab dsolve and 'by hand' discrepancies - second order ODE

1. ## Matlab dsolve and 'by hand' discrepancies - second order ODE

Hi

I've recently starting using Matlab and am trying to verify all work that I do by hand using it.

y'' + 4y' + 3y = 5e^-3x

By hand I get

y = A/e^x + B/e^3x - 5x/(2e^3x)

but with dsolve, there's an extra term ...

dsolve('D2y + 4*Dy + 3*y = 5*exp(-x*3)','x')

ans = C5/exp(x) - (5*x)/(2*exp(3*x)) - 5/(4*exp(3*x)) + C6/exp(3*x)

I can't work out what is going on - the ODE is simple to solve by hand so have I made a silly mistake in the matlab implementation?

Thanks for having a look!

Iota

2. Originally Posted by iota
Hi

I've recently starting using Matlab and am trying to verify all work that I do by hand using it.

y'' + 4y' + 3y = 5e^-3x

By hand I get

y = A/e^x + B/e^3x - 5x/(2e^3x)

but with dsolve, there's an extra term ...

dsolve('D2y + 4*Dy + 3*y = 5*exp(-x*3)','x')

ans = C5/exp(x) - (5*x)/(2*exp(3*x)) - 5/(4*exp(3*x)) + C6/exp(3*x)

I can't work out what is going on - the ODE is simple to solve by hand so have I made a silly mistake in the matlab implementation?

Thanks for having a look!

Iota
Both solutions are correct, you can combine the last two terms in the Matlab solution to get your solution.

Quite why M. can't sort this out I don't know.

CB

3. Originally Posted by CaptainBlack
Both solutions are correct, you can combine the last two terms in the Matlab solution to get your solution.

Quite why M. can't sort this out I don't know.

CB
Thanks CB - of course, it's just a constant term!

Even if I had noticed that I would have still been a little confused. What is really interesting me now though is the underlying algorithm used by M. Where would it have got that value, separate from the other constant term, from? I will try to do some searching about. Would be interesting to see how other symbolic solvers behave.

Cheers!

i

4. Originally Posted by iota
Thanks CB - of course, it's just a constant term!

Even if I had noticed that I would have still been a little confused. What is really interesting me now though is the underlying algorithm used by M. Where would it have got that value, separate from the other constant term, from? I will try to do some searching about. Would be interesting to see how other symbolic solvers behave.

Cheers!

i
It will be due to its way of finding a particular integral, and I suspect it then does not realise it can combine similar terms one with a numeric constant coefficient and the other with a symbolic constant coefficient.

CB