Help with Laplace transform method for 2nd order DE

6 ビュー (過去 30 日間)
Nina
Nina 2023 年 4 月 23 日
回答済み: Star Strider 2023 年 4 月 23 日
I'm trying to solve the equation: y'' +2y' +y = g(t), with g(t) = { sin(t) if t < pi, 0 if t < pi }, and the intial conditons y(0) = 0 and y'(0) = 0.
Here's the code that I've tried:
syms s t y(t) Y
g = heaviside(t)*(sin(t)) + heaviside(t - pi)*(-sin(t));
eqn = diff(y,2) + 2*diff(y) + 2*(y) == g;
lteqn = laplace(eqn, t, s);
neweqn = subs(lteqn, [laplace(y(t), t, s), y(0), subs(diff(y(t), t, 0)), [Y, 0, 0]]);
ytrans = simplify(solve(neweqn, Y));
Warning: Unable to find explicit solution. For options, see help.
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
> In sym/solve (line 317)
>> y = ilaplace(ytrans, s, t)
y =
Empty sym: 0-by-1
I'm not sure why ytrans is not finding a solution. Can someone help me fix this/ find a different method?

採用された回答

Star Strider
Star Strider 2023 年 4 月 23 日
In the subs call, use curly braces {} instead of square brackets [].
Then, it works —
syms s t y(t) Y
g = heaviside(t)*(sin(t)) + heaviside(t - pi)*(-sin(t));
eqn = diff(y,2) + 2*diff(y) + 2*(y) == g;
lteqn = laplace(eqn, t, s);
neweqn = subs(lteqn, {laplace(y(t), t, s), y(0), subs(diff(y(t), t), t, 0)}, {Y, 0, 0})
neweqn = 
ytrans = simplify(solve(neweqn, Y));
y = ilaplace(ytrans, s, t)
y = 
figure
fplot(y, [0 10])
grid
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by