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

 Réponse acceptée

Sam Chak
Sam Chak le 9 Mai 2022

2 votes

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 commentaires

Do Son
Do Son le 9 Mai 2022
Thanks, it really works.
Do Son
Do Son le 9 Mai 2022
But can you explain why my code didn't work?
Sam Chak
Sam Chak le 9 Mai 2022
Because subs takes a maximum of 3 arguments. Maximum 2 commas.
Do Son
Do Son le 10 Mai 2022
If you could fix on my code, how would you do that?
Sam Chak
Sam Chak le 10 Mai 2022
Modifié(e) : Sam Chak le 10 Mai 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)

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2021a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by