I have a problem with finding inverse laplace of function with Matlab. I obtained following transfer function :
I tried methods like
syms s t;
num=[0 0 0 1.658e24 -1.163e14 6.076e15];
den=[1 3.334e09 1.005e15 1.675e24 5.025e27 1.675e33];
numsym=poly2sym(num);
densym=poly2sym(den);
transfer=numsym./densym;
ilaplace(transfer,s,t)
but did not get an acceptable result. Meaning Matlab simply returns :
Also I tried to use partial fraction expansion and I wrote transfer function respect to poles and zeros but when I added all the pieces I did not get the original transfer function.
syms s t;
num=[0 0 0 1.658e24 -1.163e14 6.076e15];
den=[1 3.334e09 1.005e15 1.675e24 5.025e27 1.675e33];
numsym=poly2sym(num);
densym=poly2sym(den);
transfer=numsym./densym;
[z,p,r]=residue(num,den);
transfer1=(z(1)/(s-p(1)))+(z(2)/(s-p(2)))+(z(3)/(s-p(3)))+(z(4)/(s-p(4)))+(z(5)/(s-p(5)));
transfer1=vpa(simplifyFraction((transfer1),'Expand',true),2)
the
The transfer1 variable after simplification is order 4 in numerator while the original transfer function is order 2. I would be very thankful if anyone help me to find the transfer function of following expression by any method?
There are two things to consider:
poly2sym
without a second argument to define the desired variable, x
is being used. So poly2sym([1 1])
returns x + 1
. Here you want a polynom with variable s
, because in ilaplace
you state s
being the initial variable. Therefore use poly2sym([1 1],s)
which will give you s + 1
as result.symsum
and RootOf
which originate from the algorithm behind ilaplace
. With the command vpa
you can eliminate this and get a numerical result as far as possible.The code would be something like this:
syms s t;
num=[0 0 0 1.658e24 -1.163e14 6.076e15];
den=[1 3.334e09 1.005e15 1.675e24 5.025e27 1.675e33];
numsym=poly2sym(num,s); % here the s as second argument
densym=poly2sym(den,s); % here the s as second argument
transfer=numsym./densym;
timeexp = ilaplace(transfer,s,t);
timenum = vpa(timeexp); % get numerical answer
pretty(timenum) % show the answer in nicer form
Now we can verify the answer in case you think this might be just a bunch of numbers. Therefore a comparison with WolframAlpha is helpful. We need to convert the symbolic expression to a function handle to plot the results:
timefun = matlabFunction(timenum);
a = linspace(0,1e-4,10000);
plot(a,real(timefun(a)))
This gives the following result:
Compared to WolframAlpha, we can say that our result is definitely plausible.