How to solve system of ODE's with Boundary Conditions using BVP4C? (I would be very helpful for you)

3 views (last 30 days)
Can somebody explain me how to solve ODE's with boundary conditions using BVP4C? I've attached my ODEs with boundary conditions (and also graphs attached). Please assist me in coding this equation using BVP4C. Thank you ahead of time.
Note: M=0.0, 0.5, 1.0, 1.5 and 2.0
I would be very helpfull for your help.

Accepted Answer

Torsten
Torsten on 8 Apr 2023
M = [0 0.5 1 1.5 2];
for i = 1:numel(M)
bvpfcn = @(x,y)[y(2);y(3);-y(1)*y(3)+y(2)^2+M(i)*y(2);2*y(3)+2*y(1)*y(2)];
bcfcn = @(ya,yb)[ya(1);ya(2)-1.0;ya(4);yb(2)];
xmesh = linspace(0,5,50);
solinit = bvpinit(xmesh,[0 0 0 0]);
sol{i} = bvp4c(bvpfcn, bcfcn, solinit);
end
figure(1)
plot(sol{1}.x,sol{1}.y(1,:),sol{2}.x,sol{2}.y(1,:),sol{3}.x,sol{3}.y(1,:),sol{4}.x,sol{4}.y(1,:),sol{5}.x,sol{5}.y(1,:))
figure(2)
plot(sol{1}.x,sol{1}.y(2,:),sol{2}.x,sol{2}.y(2,:),sol{3}.x,sol{3}.y(2,:),sol{4}.x,sol{4}.y(2,:),sol{5}.x,sol{5}.y(2,:))
figure(3)
plot(sol{1}.x,sol{1}.y(3,:),sol{2}.x,sol{2}.y(3,:),sol{3}.x,sol{3}.y(3,:),sol{4}.x,sol{4}.y(3,:),sol{5}.x,sol{5}.y(3,:))
figure(4)
plot(sol{1}.x,sol{1}.y(4,:),sol{2}.x,sol{2}.y(4,:),sol{3}.x,sol{3}.y(4,:),sol{4}.x,sol{4}.y(4,:),sol{5}.x,sol{5}.y(4,:))

More Answers (1)

Torsten
Torsten on 30 Mar 2023
Edited: Torsten on 30 Mar 2023
Your remaining task: A loop over the values of M.
M = 1.0;
bvpfcn = @(x,y)[y(2);y(3);-y(1)*y(3)+y(2)^2+M*y(2);2*y(3)+2*y(1)*y(2)];
bcfcn = @(ya,yb)[ya(1);ya(2)-1.0;ya(4);yb(2)];
xmesh = linspace(0,5,50);
solinit = bvpinit(xmesh,[0 0 0 0]);
sol = bvp4c(bvpfcn, bcfcn, solinit);
plot(sol.x, sol.y(1:2,:), '-o')
  5 Comments
Torsten
Torsten on 31 Mar 2023
Edited: Torsten on 31 Mar 2023
The forum is no place where experienced MATLAB users do the tasks of users who have no experience with the software.
I already did most of the work by setting up your problem and applying "bvp4c" to it. Making a loop over the elements of M is a task that everybody who uses MATLAB should be able to do. If you have to continue using MATLAB, it's absolutely necessary for you to get the basics. That's why I suggested the online tutorial. If you don't want to get the basics, it's your decision, but in this case, it makes no sense starting to use the software at all.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements 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!