# Laplace transform of differential equations

12 views (last 30 days)
Antony Novrianto on 9 Dec 2020
Answered: Raunak Gupta on 17 Dec 2020
% Program 4_1
clear
clc
%%Transformasi Laplace dari persamaan differensial
syms x(t) y(t) s X Y
dx=diff(x,t);
dy=diff(y,t);
ddy=diff(diff(y,t),t);
hkiri=ddy+4*dy-5*y;
hkanan=dx+x;
Hkiri=laplace(hkiri,t,s);
Hkanan=laplace(hkanan,t,s);
%substitusi kondisi awal
Hskiri=subs(Hkiri,{'laplace(y(t),t,s)','y(0)','D(y)(0)'},{Y,0,0});
Hskanan=subs(Hkanan,{'laplace(x(t),t,s)','x(0)'},{X,0});
Hskiri=collect(Hskiri,Y);
Hskanan=collect(Hskanan,X);
Hs=Hskanan/Hskiri;
Hs=subs(Hs,{X,Y},{1,1});
%%Respon y(t) dengan input step
%input=x(t)=u(t)
%X(s)=laplace(u(t))=1/s
%Y(s)=H(s)*X(s)
Ys=Hs*1/s;
y=ilaplace(Ys);
pretty(y)
%Konversi Syms ke Transfer Function
[n, d]=numden(Hs);
Hs=tf(sym2poly(n),sym2poly(d));
%Pole Zero Map
subplot(2,1,1)
pzmap(Hs)
subplot(2,1,2)
stepplot(Hs)
Error using sym>convertChar (line 1557)
Character vectors and strings in the first argument can only specify a variable or
number. To evaluate character vectors and strings representing symbolic expressions, use
'str2sym'.
S = convertChar(x);
Error in sym (line 229)
Error in sym/subs>@(x)sym(x) (line 166)
X = cellfun(@(x)sym(x),X,'UniformOutput',false);
Error in sym/subs>normalize (line 166)
X = cellfun(@(x)sym(x),X,'UniformOutput',false);
[X2,Y2,symX,symY] = normalize(X,Y); %#ok
Error in sym/subs (line 145)
Error in P_4_1 (line 14)
Hskiri=subs(Hkiri,{'laplace(y(t),t,s)','y(0)','D(y)(0)'},{Y,0,0});

Raunak Gupta on 17 Dec 2020
Hi,
Here laplace(y(t),t,s) , y(0) , subs(diff(y(t),t),t,0) , laplace(x(t),t,s) , x(0) are already defined symbolic variable in equations of the starting lines. So, mentioning them as a character vector will through the error as you got. You can directly use the variable names in subs function and it will work fine.
Below changes to the Line 14 and 15 will resolve the errors.
Hskiri=subs(Hkiri,{laplace(y(t),t,s),y(0),subs(diff(y(t), t), t, 0)},{Y,0,0});
Hskanan=subs(Hkanan,{laplace(x(t),t,s),x(0)},{X,0});