how to solve laplace transform problem in matlab

58 views (last 30 days)
Capture.PNG
  8 Comments
David Goodmanson
David Goodmanson on 21 Jun 2023
Edited: David Goodmanson on 21 Jun 2023
Hi Paul,
Possibly the reason that you have not seen a statement about unilateral being applied to bilateral situations is that the number of functions with a bilateral transform is very limited compared to functions with a unilateral transform.
For the capacitor I tend to think of this from physics point of view where all times exist, so -inf <= t <= inf. Before the switch is closed at t = 0, the capacitor is sitting at a constant V0 for all t<0. For a time constant RC = tau,
V = V0 t<0 (a)
V = V0*exp(-t/tau) t>=0
which in terms of heaviside is your last expression. If that's plotted for all times it makes sense physically.
Of course as you say there are other ways to look at this, one way being your second expression
V = 0 t<0 (b)
V = V0*exp(-t/tau) t>=0
where V(0) = V0 is an initial condition. If that's plotted for all times there is a big unphysical jump in voltage at t=0, but if one knows what is going on Laplacewise, it makes sense mathematically.
Contrast that with the situation of an inductor connected to a resistor in parallel with a switch, with the switch initially closed. For t<0 , a constant current I0 flows. When the switch is opened at t=0, the current is forced through the resistor. For a time constant L/R = tau, the voltage across the inductor is
V = 0 t<0 (c)
V = I0*R*exp(-t/tau) t>=0
which has the same form as (b) but here the jump at t = 0 really is there physically.
Anyway I have to take back my previous comment objecting to f(t) = 0 for t<0 in general. I agree with you that one can always have that condition, although I also think it's misleading sometimes.
Paul
Paul on 4 Aug 2023
After reflection, I agree that whether or not the heaviside should be multiplied onto the solution of the non-zero initial value problem depends on what the underlying equations and the solution is intended to physically represent.

Sign in to comment.

Answers (4)

Star Strider
Star Strider on 16 Feb 2019
We do not know what you did to solve this. (Always post what you’ve already attempted.) However, if you got frustrated, that is easily understandable.
After a few frustrating minutes dealing with the Symbolic Math Toolbox Laplace transforms...
Try this:
syms s t T Y y(t) y0 Y(s)
Dy = diff(y);
D2y = diff(Dy);
Eqn = D2y + 4*Dy + 3*y;
LapEqn = laplace(Eqn);
LapEqn = subs(LapEqn, {laplace(y(t), t, s), subs(diff(y(t), t), t, 0), y(0)}, {Y(s), 0, 0})
Ys(s) = simplify(LapEqn/Y)
producing finally (after all that):
Ys(s) =
s^2 + 4*s + 3
The time-domain solution (such as it is) is then:
yt = ilaplace(Ys,s,t)
yt =
3*dirac(t) + 4*dirac(1, t) + dirac(2, t)
If you are just beginning to use the MATLAB Symbolic Math Toolbox, I would not expect that you would be able to work with it in this context. This should quite definitely not be as difficult as it is.
  2 Comments
Gerard Nagle
Gerard Nagle on 12 Apr 2020
Hi Star Strider,
Great solution, i was spending a lot of time trying to work out the exactly the same question, and the MATLAB help and documented example is not really great. I do have a question on your answer.
In the question posed, where did the =1 on the RHS of the differential go in the answer?
What is the use of the y0 in the syms line.
I took your solution, applied it to the equation with inital conditions and and got out the answer.
syms s t T Y y(t) y0 Y(s)
Dy = diff(y);
D2y = diff(Dy);
Eqn = D2y - Dy - 2*y == 5;
LapEqn = laplace(Eqn);
LapEqn = subs(LapEqn, {laplace(y(t), t, s), subs(diff(y(t), t), t, 0), y(0)}, {Y(s), 0, 0});
Ys(s) = simplify(LapEqn/Y);
pretty(Ys(s))
answer is
2
s Y(s) (- s + s + 2) == -5 and Y(s) ~= 0
which is or rearranged to which is the other option for the soluton, as done by hand.
My question is, do we know why MATLAB gives the warning ? something to do with zero inital conditions?
When I then try the inverse Lapalce,
yt = ilaplace(Ys,s,t)
I get the errors
Error using symengine
First argument must be of type 'Type::Arithmetical'.
Error in transform (line 74)
F = mupadmex('symobj::vectorizeSpecfunc', f.s, x.s, w.s, trans_func, 'infinity');
Error in sym/ilaplace (line 31)
F = transform('ilaplace', 's', 't', 'x', L, varargin{:});
the actual answer by hand is
Konard Adams
Konard Adams on 30 Apr 2021
Edited: Konard Adams on 30 Apr 2021
%% Solving 2nd order ODE using laplace transform
clc, clear , close all
%% Consider the initial value problem : y" - y' - 2 y = 5 , y(0) = 0 , y'(0) = 0
syms s t Y
% Defining the right-hand side function and find its Laplace transform
f = 5;
F = laplace(f,t,s);
% Finding the Laplace transform of y'(t) : Y1 = s Y - y(0)
Y1 = s*Y - 0;
% Finding the Laplace transform of y''(t) : Y2 = s Y1 - y'(0)
Y2 = s*Y1 - 0;
% Setting the Laplace transform of the left hand side minus the right hand side to zero and solve for Y:
Sol = solve(Y2 -Y1 - 2*Y - F, Y);
Solexp1= expand(Sol);
disp('Expanded Laplace Solution = '), disp(Solexp1)
Solsim1= simplify(Sol);
disp('Simplified Laplace Solution = '), disp(Solsim1)
% Finding the inverse Laplace transform of the solution
solin = ilaplace(Sol,s,t);
Solexp2= expand(solin);
disp('Expanded Inverse Laplace Solution = '), disp(Solexp2)
Solsim2= simplify(solin);
disp('Simplified Inverse Laplace Solution = '), disp(Solsim2)

Sign in to comment.


Konard Adams
Konard Adams on 30 Apr 2021
@Gerard Nagle I tried this code if it's any good and you can make it any better plesae let me know.
%% Solving 2nd order ODE using laplace transform
clc, clear , close all
syms x y t s X F
eqn = str2sym('diff(x(t),t,t)-diff(x(t),t)-2*y(t)= 5'); % Converting from string to an equation
F = laplace(eqn,s); % solving using laplace transform
eqn2 = str2sym('laplace(x(t),t,s)');
F = subs(F,{eqn2},{X}); % substituting the initial values then solve Laplace
eqn3 = str2sym('x(0)'); % Converting from string to an equation (initial values)
eqn4 = str2sym('Dx(0)'); % Converting from string to an equation (initial values)
F = subs(F,{eqn3,eqn4},{0,0}); % initial values
solx = solve(F,X);
solx = ilaplace(solx);
solxep = expand(solx); %pretty(x);
disp('Expanded Solution = '),disp(solxep)
solxsim = simplify(solx); %pretty(x);
disp('Simplified Solution = '),disp(solxsim)

Jokita harini
Jokita harini on 23 Feb 2023
y''-6y'+8y=0,y(0)=-1,y'(0)=2

Maadh
Maadh on 24 May 2023
120/s^6-1/(s-4)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!