MATLAB: Wrong differential equation solution

differential equationssymbolicSymbolic Math Toolboxwrong answer

Hello guys, I have been struggling with a differential equation. I solved it manually, and then double-checked my answer both manually and with Wolfram Alpha, and the answer was right. However, matlab seems to give another answer. The two answers are supposed to be the same, just written in different forms. However, after I copied the Wolfram Alpha answer to matlab, I found out that they are actually not equal.Did I do anything wrong? Thank you.

Best Answer

Sorry. I don't know what you did incorrectly, but here is what I see.
syms y(t)
yalpha = (1/80)*(36*exp(-t) + 125*sin(t) -3*sin(3*t) -35*cos(t) -cos(3*t));
ode = diff(y,t,3) + diff(y,t,2) + diff(y,t) + y == cos(3*t);
dy = diff(y,t);
ddy = diff(y,t,2);
ysol = simplify(dsolve(ode,y(0) == 0,dy(0) == 1,ddy(0) == 1))
ysol =
(9*exp(-t))/20 - (2*cos(t))/5 + (8*sin(t))/5 - cos(t)^3/20 - (3*cos(t)^2*sin(t))/20
simplify(ysol - yalpha)
ans =
0
The difference is identically zero. You may have copied something incorrectly. It is difficult to know, because we don't truly know what is inside the variables you claim have created.