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
% MATLAB code to Solve Initial Value Second Order
% Differential Equation Problem using Laplace Transform:
% To clear all variables from the current workspace
clear all
clc
disp("Solving Initial Value 2nd Order Differential Equation
Problem using Laplace Transform in MATLAB | GeeksforGeeks")
% To Declare them as Variables
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]: ');
% Coefficients of the 2nd Order Differential Equation
a=F(1);b=F(2);c=F(3);
% R.H.S of the 2nd Order Differential Equation
nh=input('Enter the non-homogeneous part f(x) :');
% 2nd Order Differential Equation Formed
equation=(a*d2y(t)+b*dy(t)+c*y(t)-nh);
LTY=laplace(equation,t,s);
% Initial Value Conditions
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: ")
% Y = L(y)
LTY=subs(LTY,laplace(y(t),t,s),Y)
% Substitute the Initial Value Condition-1 (y(0))
LTY=subs(LTY,y(0),y0);
% Substitute the Initial Value Condition-2 (y'(0))
LTY=subs(LTY,subs(diff(y(t),t),0),dy0);
% Collect the 'Y' Terms (L(y) terms)
eq=collect(LTY,Y);
disp("After Simplification, L(y) is: ")
% Simplify 'Y'
Y=simplify(solve(eq,Y))
% Find Inverse Laplace of 'Y' (ILap(Y)=ILap(L(y))=y))
yt=simplify(ilaplace(Y,s,t));
disp('The solution of the differential equation y(t)=')
disp(yt);
% Displaying the Plot of y(t) Found
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
% MATLAB code to Solve Initial Value Second Order
% Differential Equation Problem using Laplace Transform:
% To clear all variables from the current workspace
clear all
clc
disp("Solving Initial Value 2nd Order Differential Equation
Problem using Laplace Transform in MATLAB | GeeksforGeeks")
% To Declare them as Variables
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]: ');
% Coefficients of the 2nd Order Differential Equation
a=F(1);b=F(2);c=F(3);
% R.H.S of the 2nd Order Differential Equation
nh=input('Enter the non-homogeneous part f(x) :');
% 2nd Order Differential Equation Formed
equation=(a*d2y(t)+b*dy(t)+c*y(t)-nh);
LTY=laplace(equation,t,s);
% Initial Value Conditions
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: ")
% Y = L(y)
LTY=subs(LTY,laplace(y(t),t,s),Y)
% Substitute the Initial Value Condition-1 (y(0))
LTY=subs(LTY,y(0),y0);
% Substitute the Initial Value Condition-2 (y'(0))
LTY=subs(LTY,subs(diff(y(t),t),0),dy0);
% Collect the 'Y' Terms (L(y) terms)
eq=collect(LTY,Y);
disp("After Simplification, L(y) is: ")
% Simplify 'Y'
Y=simplify(solve(eq,Y))
% Find Inverse Laplace of 'Y' (ILap(Y)=ILap(L(y))=y))
yt=simplify(ilaplace(Y,s,t));
disp('The solution of the differential equation y(t)=')
disp(yt);
% Displaying the Plot of y(t) Found
ezplot(yt,[y0, y0+2]);
Output:
d^2y/dt^2 - 2dy/dt + y = e^t, y(0)=2 ,y'(0)=-1
Similar Reads
Practice Problems on Laplace Transforms | Simplified Method for Solving Differential Equation Laplace transform is one of the useful mathematical tools used in engineering mathematics, applied mathematics and sciences to solve several difficult problems. It transforms time and its associated measure (time domain function) into a complex frequency domain function and makes the complex problem
5 min read
Runge-Kutta 2nd order method to solve Differential equations // Given the following inputs:Â An ordinary differential equation that defines the value of dy/dx in the form x and y.[latex]\LARGE \frac{dy}{dx} = f(x, y)[/latex]Initial value of y, i.e., y(0).[latex]\LARGE y(0)= y_o[/latex] The task is to find the value of unknown function y at a given point x, i.e.
8 min read
Solving 2nd Order Homogeneous Difference Equations in MATLAB Difference Equations are Mathematical Equations involving the differences between usually successive values of a function ('y') of a discrete variable. Here, a discrete variable means that it is defined only for values that differ by some finite amount, generally a constant (Usually '1'). A differen
4 min read
Gill's 4th Order Method to solve Differential Equations Given the following inputs: An ordinary differential equation that defines the value of dy/dx in the form x and y.[latex]\LARGE \frac{dy}{dx} = f(x, y)[/latex]Initial value of y, i.e., y(0).[latex]\LARGE y(0)= y_o[/latex] The task is to find the value of the unknown function y at a given point x, i.
10 min read
Runge-Kutta 4th Order Method to Solve Differential Equation Given the following inputs, An ordinary differential equation that defines value of dy/dx in the form x and y.Initial value of y, i.e., y(0) Thus we are given below.\frac{\mathrm{dy} }{\mathrm{d} x} = f(x, y),y(0)= y_o The task is to find the value of the unknown function y at a given point x.The Ru
10 min read