I want to treat w as a constant

3 次查看(过去 30 天)
현국 조
현국 조 2021-10-31
重新打开: Walter Roberson 2021-10-31
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?

回答(2 个)

David Goodmanson
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

Walter Roberson
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]
conds = 
ySol(x) = dsolve(ode,conds);
ySol = simplify(ySol)
ySol(x) = 
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})
ans = 

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by