Borrar filtros
Borrar filtros

Solution of second order BVP with variable functions

24 visualizaciones (últimos 30 días)
Ashok Das
Ashok Das el 29 de En. de 2024
Respondida: Sandeep Mishra el 19 de Sept. de 2024 a las 8:29
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

Respuestas (1)

Sandeep Mishra
Sandeep Mishra el 19 de Sept. de 2024 a las 8:29
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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by