how to remove error form BVP4C code
4 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Monte Carlo Analysis 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!