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);

 Accepted Answer

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 Comments

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?
Sam Chak
Sam Chak on 10 May 2022
Edited: Sam Chak on 10 May 2022
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)

Sign in to comment.

More Answers (0)

Products

Release

R2021a

Tags

Asked:

on 9 May 2022

Edited:

on 10 May 2022

Community Treasure Hunt

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

Start Hunting!