Plotting Step Response of a Differential Equation

17 ビュー (過去 30 日間)
Bailey Smith
Bailey Smith 2019 年 5 月 23 日
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
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
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))

カテゴリ

Help Center および File ExchangeEngines & Motors についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by