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

 채택된 답변

Sam Chak
Sam Chak 2022년 5월 9일

2 개 추천

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

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

카테고리

제품

릴리스

R2021a

태그

질문:

2022년 5월 9일

편집:

2022년 5월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by