- 'bvp4c': https://www.mathworks.com/help/matlab/ref/bvp4c.html
- 'bvp5c': https://www.mathworks.com/help/matlab/ref/bvp5c.html
Is it possible to solve multiple ODEs using bvp5c/bvp4c?
18 views (last 30 days)
Show older comments
Hi MathWorks Community!
I have a system of six ODEs, 4 of which have the boundaries [0, 1]. I have so far used ODE45, however this has at times resulted in negative values and thereby violated the boundaries. Is it possible to use bvp5c/bvp4c, or should I rather go for ODE event location (ref. the bouncing ball problem)?
Additionally, is there a way of shortening computational time? F.ex. by defining the specific times at which I want a solution, rather than calculating a matrix greater than 1 000 000x6.
0 Comments
Answers (1)
Manikanta Aditya
on 27 Feb 2024
Hi Thomas,
Looks like you can solve multiple ODEs using 'bvp4c' or 'bvp5c' in MATLAB. These functions are especially desgined for solving boundary value problems, which seems to be what you're dealing with.
Here is a basic example of how you might set up a system of two ODEs with 'bvp4c':
function dydx = odefun(x, y)
dydx = [y(2); % y1'
-y(1)]; % y2'
end
function res = bcfun(ya, yb)
res = [ya(1); % y1(a) = 0
yb(1)-1]; % y1(b) = 1
end
% You can run these commands from command window after defining the
% functions
solinit = bvpinit(linspace(0, 1, 5), [0 0]);
sol = bvp4c(@odefun, @bcfun, solinit);
In this example, 'odefun' defines the system of ODEs and bcfun defines the boundary conditions. 'bvpinit' is used to create an initial guess for the solution, which is then refined by 'bvp4c'.
As for your question about computational time, one way to potentially reduce it is by providing a more accurate initial guess to 'bvp4c' or 'bvp5c'. The closer your initial guess is to the actual solution, the fewer iterations these functions will need to converge.
If you’re finding that the matrix you’re working with is too large, you might also consider whether there are any symmetries or other properties of your system that you can take advantage of to reduce its size.
Regarding the use of event location as in the bouncing ball problem, this is typically used for problems where the solution has discontinuities, or where you want to stop the integration once a certain condition is met. If your problem doesn’t have these characteristics, 'bvp4c' or 'bvp5c' might be more appropriate.
Refer the following references to know more about
I hope it 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!