Plotting Step Response of a Differential Equation
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Manivanna Boopathi Arumugam
le 11 Avr 2021
Just assign the solution as a matlabfunction and do functionplot.
t_max=5;
xSoln = matlabFunction(xSoln);
fplot(xSoln,[0 t_max])
Réponses (1)
David Wilson
le 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 commentaires
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!