How can i fix this error ?

syms s t Y
LHS = laplace(diff(diff(str2sym('y(t)')))+2*diff(str2sym('y(t)')));
RHS = laplace(8*t);
newLHS = subs(LHS,'laplace(y(t),t,s)','y(0)','D(y)(0)',Y,0,0);
Error using sym/subs
Too many input arguments.
Y = solve(newLHS-RHS,Y);
y = ilaplace(Y,s,t);
Error using sym/subs
Too many input arguments.
Error in Chay_thu_nghiem (line 4)
newLHS = subs(LHS,'laplace(y(t),t,s)','y(0)','D(y)(0)',Y,0,0);

 采纳的回答

Try this:
% to formulate ODE
syms s t y(t) Y(s)
D1y = diff(y);
D2y = diff(D1y);
Eqn = D2y + 2*D1y == 8*t
% to obtain the transfer function
LEqn = laplace(Eqn)
LEqn = subs(LEqn, {laplace(y(t), t, s), y(0), D1y(0)}, {Y(s), 0, 0})
LEqn = isolate(LEqn, Y(s))
% to solve ODE via taking the inverse Laplace transforms of transfer function
y(t) = ilaplace(rhs(LEqn))

5 个评论

Thanks, it really works.
But can you explain why my code didn't work?
Because subs takes a maximum of 3 arguments. Maximum 2 commas.
If you could fix on my code, how would you do that?
I tried avoiding lot of parentheses () and a clump of characters without spacing because they make tracing your own code and debugging very unfriendly to read and troubleshoot. Start following good coding practices.
This should work now:
syms s t y(t) Y
D1y = diff(y);
D2y = diff(D1y);
% Left-hand side
LHS = laplace(D2y + 2*D1y);
LHS = subs(LHS, {laplace(y(t), t, s), y(0), D1y(0)}, {Y, 0, 0})
% Right-hand side
RHS = laplace(8*t)
% Laplace equation
LEqn = LHS - RHS == 0
Y = solve(LEqn, Y)
y = ilaplace(Y, s, t)

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Function Creation 的更多信息

产品

版本

R2021a

标签

Community Treasure Hunt

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

Start Hunting!

Translated by