Solution of ODE with Symbolic Math Toolbox.

Hello,
I want to solve the ordinary differential equation
with , , . The function and should be a unity step. In other words: it is the step response of a first order lag element. I am using the Symbolic Math Toolbox.
First I define the variables including the relevant assumptions.
syms("t", "positive")
syms("T_1", "k_p", "positive")
syms("u(t)", "y(t)")
The I establish the differential equation
deq = T_1 * diff(y, t) + y == k_p * u
deq(t) = 
and replace with the unist step function.
deq = subs(deq, u, heaviside(t))
deq(t) = 
The solution
y_sol_t = dsolve(deq, y(0) == 0)
y_sol_t = 
y_sol_t = simplify(y_sol_t)
y_sol_t = 
is not very clear for students. It is hard to see that for .
If I use the Laplace Transform instead I get: the following result.
Laplace Transform of the above differential equation.
syms("s")
aeq = laplace(deq, t, s)
aeq = 
syms("y_LT")
Replacing laplace(y(t), t, s) and the initial condition
aeq = subs(aeq, [laplace(y(t), t, s) y(0)], [y_LT, 0])
aeq = 
Solve the algbraic equation vor y_LT
y_LT = solve(aeq, y_LT)
y_LT = 
Inverse Laplace Transform
y_sol_LT = ilaplace(y_LT, s, t)
y_sol_LT = 
which is valid only for , but can be extended to the general solt ion by multiplying it with ethe unit step.
y_sol_LT = y_sol_LT * heaviside(t)
y_sol_LT = 
How can I obtain this solution from the result calculated using dsolve?
Michael

 Respuesta aceptada

Paul
Paul el 27 de Abr. de 2026
Use rewrite to get the solution in terms of heaviside.
syms("t", "positive")
syms("T_1", "k_p", "positive")
syms("u(t)", "y(t)")
deq = T_1 * diff(y, t) + y == k_p * u;
deq = subs(deq, u, heaviside(t));
y_sol_t = dsolve(deq, y(0) == 0)
y_sol_t = 
y_sol_t = simplify(y_sol_t)
y_sol_t = 
y_sol_t = rewrite(y_sol_t,'heaviside') % makes clear the solution is 0 for t < 0
y_sol_t = 
To get the exact same result as from Laplace ... an easy, if not elegant, approach
simplify(y_sol_t/heaviside(t))*heaviside(t)
ans = 

1 comentario

Michael
Michael el 28 de Abr. de 2026
Thank you for showing mne the use of rewrite with the heaviside argument. Altough I am using this function in aother contexts, I was not aware of using it with heaviside.
After ereading your approach; I was playing alittle bit with collect and combine statements, however your easy approach in the last line is the only one giving the expected result.
What I simply don't understand: I make an assumption for the variable t, which should be poitive and I set an initial condition for t=0. So it should be obvious, that the interesting solution should start at t=0.
Michael

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2025b

Preguntada:

el 27 de Abr. de 2026

Comentada:

el 28 de Abr. de 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by