I want to treat w as a constant
3 次查看(过去 30 天)
显示 更早的评论
syms y(x)
ode = diff(y,x,2) +2*diff(y,x) +(w^2+1)*y == 0;
Dy = diff(y);
cond1 = y(0) == 1
cond2 = Dy(0) == 0
conds = [cond1 cond2]
ySol(x) = dsolve(ode,conds);
ySol = simplify(ySol)
the answer is
exp(-x)*(cos(wx)+1/w*sin(wx))
how can I get the answer?
0 个评论
回答(2 个)
David Goodmanson
2021-10-31
Hello HJ,
try replacing the first line with
syms y(x) w real
in which case the result is
ySol(x) =
(exp(-x)*(sin(w*x) + w*cos(w*x)))/w
0 个评论
Walter Roberson
2021-10-31
syms y(x)
syms w real
ode = diff(y,x,2) +2*diff(y,x) +(w^2+1)*y == 0;
Dy = diff(y);
cond1 = y(0) == 1;
cond2 = Dy(0) == 0;
conds = [cond1 cond2]
ySol(x) = dsolve(ode,conds);
ySol = simplify(ySol)
To get from that to what you want is sightly tricky. MATLAB has "preferred" ways to express terms, and you need to force it to overwride that preferred forms. That is, the output is already equivalent to what you want, but to force it to be written the same way you want you need to take a couple of steps that are not obvious.
ch = children(ySol(x));
ch{2}*expand(ch{1}*ch{3})
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!