how to remove error form BVP4C code

4 views (last 30 days)
Syed
Syed on 5 Apr 2023
Commented: Syed on 8 Apr 2023
Respected Sir/Maam.
I was trying to solve a Nonlinear System ODE by BVP4C. Hear It is error " Error in bvp4c (line 129)" in File "marwah (attached)" and some errors, which i am not able to rectify. Can you please help. If any information is required, please feel free to ask.
Thanking you in Advance
you help will be highly apprecialbe.
% Define the values of M for which we want to solve the ODE
M_values = [0, 0.5, 1, 1.5, 2];
% Loop over the different values of M
for i = 1:length(M_values)
M = M_values(i);
% Define the anonymous functions for the ODEs
ode1 = @(eta, y) [y(2); y(3); -(y(2)^2) - y(1)*y(3) + M*y(2)];
ode2 = @(eta, y) [y(3); -2*y(2)*y(3) - 2*y(1)*y(2)];
% Define the boundary conditions
bc = @(ya, yb) [ya(1); ya(3); ya(2)-1; yb(1); yb(2); yb(3)];
% Solve the ODEs using bvp4c
eta_vals = linspace(0, 10, 1000);
init_guess = [0, 1, -1];
solinit = bvpinit(eta_vals, init_guess);
sol = bvp4c(ode1,bc,solinit);
f = sol.y(1,:);
fp = sol.y(2,:);
g = sol.y(3,:);
% Plot the graphs of f(eta), f'(eta), and g(eta)
figure;
plot(eta_vals, f, 'b', 'LineWidth', 1.5);
hold on;
plot(eta_vals, fp, 'r', 'LineWidth', 1.5);
plot(eta_vals, g, 'g', 'LineWidth', 1.5);
legend('f(eta)', 'f''(eta)', 'g(eta)');
title(['M = ', num2str(M)]);
xlabel('eta');
ylabel('f(eta), f''(eta), g(eta)');
grid on;
end
Error using bvparguments
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
The boundary condition function BCFUN should return a column vector of length 3.

Error in bvp4c (line 122)
bvparguments(solver_name,ode,bc,solinit,options,varargin);

Accepted Answer

Torsten
Torsten on 5 Apr 2023
Edited: Torsten on 5 Apr 2023
The odes you want to solve cannot be defined in two separate ODE functions.
If you want to solve two differential equations simultaneously, you have to number the unknown in an increasing manner.
E.g.
f''' = 4
g'' = 6
had to be defined with an y-vector of length 5 setting
y(1) = f
y(2) = f'
y(3) = f''
y(4) = g
y(5) = g'
and
ode = @(eta, y) [y(2); y(3); 4; y(5); 6];
Further, the number of boundary conditions must equal the number of equations.
In the code above, you define 3 equations. Thus you need 3 boundary conditions, not 6.
  1 Comment
Syed
Syed on 8 Apr 2023
Revered Sir,
Hope you are doing well.
I would like to draw your worthy attention towards error on ODE’s with boundary conditions (attached and also attached graphs).
Your good self guided me ()https://www.mathworks.com/matlabcentral/answers/1937894-how-to-solve-system-of-ode-s-with-boundary-conditions-using-bvp4c-i-would-be-very-helpful-for-you?s_tid=srchtitle) to follow loop for M=0.0, 0.5, 1.0, 1.5 and 2.0 and solve it. I tried my level best but all in vain.
I humbly request your honor to remove the error and solve the said issue.
I would be very helpfull for your help.
Thank you ahead of time.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!