Plotting Step Response of a Differential Equation
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/220759/image.png)
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/220760/image.png)
1 Kommentar
Manivanna Boopathi Arumugam
am 11 Apr. 2021
Just assign the solution as a matlabfunction and do functionplot.
t_max=5;
xSoln = matlabFunction(xSoln);
fplot(xSoln,[0 t_max])
Antworten (1)
David Wilson
am 24 Mai 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))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!