Consider $y^{\prime \prime} + y = 0$ and its solution candidate $\cos(t)$. Using MATLAB I would like to substitute the candidate into the differential equation and get verification that it is indeed a solution. How can I do this? I already know that the candidate is a solution, however, when I learn the procedure I will apply it to the other differential equations and solution candidates.
2026-04-06 20:39:14.1775507954
On
Matlab differential equation verification
163 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
0
On
Using Matlab's Symbolic Math toolbox and isAlways in particular:
syms y(t)
f = diff(y,t,2)+y;
y_sol = cos(t);
isAlways(subs(f,y,y_sol) == 0)
returns 1 indicating that the candidate is a solution. Note that if your actual differential equations are much more complicated, it may not be feasible to prove that a candidate is a solution. You may also need to use assumptions.
The general solution to your problem can be computed by Laplace Transform , and then you'll get:
$$y''(t)+y(t)=0\Longleftrightarrow$$ $$\frac{\text{d}^2y(t)}{\text{d}t^2}+y(t)=0\Longleftrightarrow$$ $$y(t)=y(0)\sin(t)+y'(0)\cos(t)\Longleftrightarrow$$ $$y(t)=c_2\sin(t)+c_1\cos(t)$$
Checking your $\cos(t)$ solution:
$$\frac{\text{d}^2}{\text{d}t^2}\cos(t)+\cos(t)=0\Longleftrightarrow$$ $$-\cos(t)+\cos(t)=0\Longleftrightarrow$$ $$\cos(t)-\cos(t)=0\Longleftrightarrow$$ $$0=0$$