Solution of second order BVP with variable functions
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponses (1)
Sandeep Mishra
le 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 commentaires
Voir également
Catégories
En savoir plus sur Boundary Value Problems dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!