Solution of second order BVP with variable functions

조회 수: 5 (최근 30일)
Ashok Das
Ashok Das 2024년 1월 29일
답변: Sandeep Mishra 2024년 9월 19일
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

답변 (1개)

Sandeep Mishra
Sandeep Mishra 2024년 9월 19일
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:
  1. ‘bvp4c’ function: https://www.mathworks.com/help/releases/R2024a/matlab/ref/bvp4c.html
  2. ‘bvp5c’ function: https://www.mathworks.com/help/releases/R2024a/matlab/ref/bvp5c.html
I hope this helps.

카테고리

Help CenterFile Exchange에서 Boundary Value Problems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by