How to plot a DE

5 次查看(过去 30 天)
Hello!
I´m in trouble plotting the result of this differential equation:
syms x_d(t_d)
ode = diff(x_d,t_d,2)+diff(x_d,t_d)-x_d == cos(w_n*t_d);
x_dSol(t_d) = dsolve(ode)
How can I do this?

采纳的回答

Walter Roberson
Walter Roberson 2021-1-22
You need specific boundary conditions in order to plot, and specific w_n value.
syms x_d(t_d)
syms w_n
ode = diff(x_d,t_d,2)+diff(x_d,t_d)-x_d == cos(w_n*t_d);
x_dSol(t_d) = dsolve(ode)
x_dSol(t_d) = 
x0 = randi([-9 9]), dx0 = randi([-9 9]), w_n0 = randi([1 300])
x0 = -9
dx0 = -3
w_n0 = 99
dx_d = diff(x_d,t_d);
ic = [x_d(0) == x0, dx_d(0) == dx0]
ic = 
ode1 = subs(ode, w_n, w_n0)
ode1(t_d) = 
%you SHOULD be able to solve with two initial conditions, but dsolve does not
%like it. So solve with x(0) boundary condition, then differentiate
%and solve for the constant
x_dSol2 = dsolve(ode1, ic(1))
x_dSol2 = 
const_var = setdiff(symvar(x_dSol2), t_d);
const_sol = solve(subs(diff(x_dSol2, t_d), t_d, 0), const_var)
const_sol = 
x_dSol3 = simplify(subs(x_dSol2, const_var, const_sol))
x_dSol3 = 
fplot(x_dSol3, [0 10])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Equation Solving 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by