# Plotting Step Response of a Differential Equation

44 views (last 30 days)
Bailey Smith on 23 May 2019
I have a differential equation whose step input is 5: . I have solved for the response, but I am unsure of how to plot it. I would also like to add a line at the steady-state for reference, if possible. If not, that's alright. Here is my code:
clear; clc;
%format
digits(4)
%set up equations
syms x(t)
Dx = diff(x,t);
D2x = diff(x,t,2);
%solve
ode = 3*diff(x,t,2)+21*diff(x,t)+30*x == 5;
cond1 = x(0) == 0;
cond2 = Dx(0) == 0;
conds = [cond1 cond2];
%results
xSol(t) = vpa(dsolve(ode,conds))
My output is . How would I go about plotting this?
Just assign the solution as a matlabfunction and do functionplot.
t_max=5;
xSoln = matlabFunction(xSoln);
fplot(xSoln,[0 t_max])

David Wilson on 24 May 2019
You are close to a viable solution. Solve for an analytical solution, then make it a Matlab (anonymous) function with matlabFunction. Then just plot as normal.
soln = dsolve(ode,conds)
x = matlabFunction(soln)
t = linspace(0,5)';
plot(t,x(t))