I want to treat w as a constant

2 Ansichten (letzte 30 Tage)
현국 조
현국 조 am 31 Okt. 2021
Erneut geöffnet: Walter Roberson am 31 Okt. 2021
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?

Antworten (2)

David Goodmanson
David Goodmanson am 31 Okt. 2021
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 am 31 Okt. 2021
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 = 

Community Treasure Hunt

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

Start Hunting!

Translated by