Laplace transform of differential equations

4 visualizzazioni (ultimi 30 giorni)
Antony Novrianto
Antony Novrianto il 9 Dic 2020
Risposto: Raunak Gupta il 17 Dic 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'.
Error in sym>tomupad (line 1273)
S = convertChar(x);
Error in sym (line 229)
S.s = tomupad(x);
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);
Error in sym/subs>mupadsubs (line 157)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok
Error in sym/subs (line 145)
G = mupadsubs(F,X,Y);
Error in P_4_1 (line 14)
Hskiri=subs(Hkiri,{'laplace(y(t),t,s)','y(0)','D(y)(0)'},{Y,0,0});

Risposte (1)

Raunak Gupta
Raunak Gupta il 17 Dic 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});

Community Treasure Hunt

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

Start Hunting!

Translated by