Solving Initial Value 2nd Order Differential Equation Problem using Laplace Transform in MATLAB
Last Updated :
29 Mar, 2022
In the domain of Multivariable calculus, the Initial value problem (IVP) is a general differential equation given together with some initial condition(s), which usually specifies the value of the unknown function at some given point(s) in its Domain. Here, Initial conditions are values of the solution and/or its derivative(s) at a specific point(s) in its domain.
Steps to Solve Initial Value Second Order Differential Equation Problem using Laplace Transform:
Step 1: Apply the Laplace Transform to the Given Equation on its Both Sides.
Step 2: Separate the ‘L(y)’ Terms after applying Laplace Transform.
Step 3: Substitute the Initial Value Conditions given along with the 2nd Order Differential Equation in the ‘L(y)’ found in the above step.
Step 4: Simplify the ‘L(y)’.
Step 5: Now, Apply the Inverse Laplace Transform on Both Sides of the above Equation. Hence. we obtained the required solution ‘y(t)’ ( Since, InvL(L(y))=>y ).
Approach:
- disp(txt): This method displays the ‘txt’.
- input(txt): This method displays the ‘txt’ and waits for the user to input a value and press the Return key.
- diff(y) (or) diff(y,x) : This method differentiates y with respect to x.
- laplace (y,t s): This method returns the Laplace Transform of, where the independent variable is ‘t’, and the transformation variable is ‘s’.
- subs(y, old, new): This method returns a copy of y, replacing all occurrences of old with new.
- ilaplace(Y,s,t): This method returns the Inverse Laplace Transform of Y, where the independent variable is s and the transformation variable is t
- ezplot(y,xinterval): This Method plots the curve y=f(x) over the specified interval ‘xinterval’.
Example 1:
Matlab
clear all
clc
disp("Solving Initial Value 2nd Order Differential Equation
Problem using Laplace Transform in MATLAB | GeeksforGeeks")
syms t s y(t) Y
dy(t)=diff(y(t));
d2y(t)=diff(y(t),2);
F=input( 'Input the coefficients [a,b,c]: ' );
a=F(1);b=F(2);c=F(3);
nh=input( 'Enter the non-homogeneous part f(x) :' );
equation=(a*d2y(t)+b*dy(t)+c*y(t)-nh);
LTY=laplace(equation,t,s);
y0=IC(1);dy0=IC(2);
IC=input( 'Enter the initial conditions in the form [y0,Dy(0)]:' );
disp( "After applying Laplace Transform on Both Sides: " )
LTY=subs(LTY,laplace(y(t),t,s),Y)
LTY=subs(LTY,y(0),y0);
LTY=subs(LTY,subs(diff(y(t),t),0),dy0);
eq=collect(LTY,Y);
disp( "After Simplification, L(y) is: " )
Y=simplify(solve(eq,Y))
yt=simplify(ilaplace(Y,s,t));
disp( 'The solution of the differential equation y(t)=' )
disp(yt);
ezplot(yt,[y0, y0+2]);
|
Output:
d^2y/dt^2 + 2dy/dt + 5y = exp(-t)(sin(t)), y(0)=0 ,y'(0)=1
Example 2:
Matlab
clear all
clc
disp("Solving Initial Value 2nd Order Differential Equation
Problem using Laplace Transform in MATLAB | GeeksforGeeks")
syms t s y(t) Y
dy(t)=diff(y(t));
d2y(t)=diff(y(t),2);
F=input( 'Input the coefficients [a,b,c]: ' );
a=F(1);b=F(2);c=F(3);
nh=input( 'Enter the non-homogeneous part f(x) :' );
equation=(a*d2y(t)+b*dy(t)+c*y(t)-nh);
LTY=laplace(equation,t,s);
y0=IC(1);dy0=IC(2);
IC=input( 'Enter the initial conditions in the form [y0,Dy(0)]:' );
disp( "After applying Laplace Transform on Both Sides: " )
LTY=subs(LTY,laplace(y(t),t,s),Y)
LTY=subs(LTY,y(0),y0);
LTY=subs(LTY,subs(diff(y(t),t),0),dy0);
eq=collect(LTY,Y);
disp( "After Simplification, L(y) is: " )
Y=simplify(solve(eq,Y))
yt=simplify(ilaplace(Y,s,t));
disp( 'The solution of the differential equation y(t)=' )
disp(yt);
ezplot(yt,[y0, y0+2]);
|
Output:
d^2y/dt^2 - 2dy/dt + y = e^t, y(0)=2 ,y'(0)=-1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...