Plotting Step Response of a Differential Equation
18 次查看(过去 30 天)
显示 更早的评论
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?
1 个评论
Manivanna Boopathi Arumugam
2021-4-11
Just assign the solution as a matlabfunction and do functionplot.
t_max=5;
xSoln = matlabFunction(xSoln);
fplot(xSoln,[0 t_max])
回答(1 个)
David Wilson
2019-5-24
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))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Engines & Motors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!