how to remove error form BVP4C code

조회 수: 7 (최근 30일)
Syed
Syed 2023년 4월 5일
댓글: Syed 2023년 4월 8일
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);

채택된 답변

Torsten
Torsten 2023년 4월 5일
편집: Torsten 2023년 4월 5일
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
Syed
Syed 2023년 4월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Monte Carlo Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by