Solution of second order BVP with variable functions
5 views (last 30 days)
Show older comments
Hello everyone,
I am trying to solve the following 2nd order BVP:
where p and q are known functions with constant parameters. I want to solve this BVP for Y, where p and q will act as know but input functions.
Can anyone help me solve this BVP?
(For the sake of simplicity, lets consider and )
Thanks in Advance!
-Ashok Das
Answers (1)
Sandeep Mishra
on 19 Sep 2024
Hi Ashok,
To solve a second-order boundary value problem (BVP) in MATLAB, you can utilize the ‘bvp4c’ and ‘bvp5c’ functions.
These functions are well-suited for handling BVPs of the form y′′(x) + sin(x)y′(x) + cos(x)y(x) = 0.
To solve the given second-order differential equation, I have made the following assumptions:
Let y1(x) = y(x) and y2(x) = y′(x), which leads to y1′(x) = y2(x) and y2′(x) = -sin(x) * y2(x) - cos(x) * y1(x).
The boundary conditions are set as: y(0) = 2 and y(1) = 3, with an initial guess for y′(0) = 0.
Refer to the following code snippet:
% Defining differential equation
function dydx = diff_eq(x, y)
% dydx = [y(2); y(2)'];
dydx = [y(2); -sin(x) * y(2) - cos(x) * y(1)];
end
% Defining boundary conditions
function res = boundary_conditions(ya, yb)
% y(0) = 2, y(1) = 3
res = [ya(1) - 2; yb(1) - 3];
end
% Initial guess for given x with y(0)=2, y’(0)=0
solinit = bvpinit(linspace(0, 1, 10), [2 0]);
% Solution using ‘bvp4c’ function
sol = bvp4c(@diff_eq, @boundary_conditions, solinit);
% Solution using ‘bvp4c’ function
sol = bvp5c(@diff_eq, @boundary_conditions, solinit);
For more information, refer to the following MathWorks documentation:
- ‘bvp4c’ function: https://www.mathworks.com/help/releases/R2024a/matlab/ref/bvp4c.html
- ‘bvp5c’ function: https://www.mathworks.com/help/releases/R2024a/matlab/ref/bvp5c.html
I hope this helps.
0 Comments
See Also
Categories
Find more on Boundary Value Problems 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!