How to set Drichlet and Neumann boundary conditions for a set of ode in BVP solver

18 Ansichten (letzte 30 Tage)
Hey everybody,
I have following problem. I have a system of coupled odes that I want to solve with a BVP solver. For the first ODE I have a Drichlet & Neumann boundary condition. For the second ode I have only a Drichlet boundary condition. Writting the code a stumbled across the problem, that there are too many boundary conditions. Is there a possibility that I can set three boundaries (mix between Drichlet and Neumann boundary) for a set of two ODE's?
Below the code:
% Define the range of the independent variable
xspan = [0, 1];
% Initial guess for the solution
solinit = bvpinit(linspace(0, 1, 5), @guess);
% Solve the BVP with bvp4c
sol = bvp4c(@odefun, @bc, solinit);
% Plot the results
xint = linspace(0, 1, 100);
yint = deval(sol, xint);
figure;
plot(xint, yint(1, :), '-o', xint, yint(2, :), '-x');
legend('y(x)', 'z(x)');
title('Solution of two separate first-order ODEs, one with Neumann BC');
xlabel('x');
ylabel('y, z');
function dydx = odefun(x, y)
a = y(1);
z = y(2);
dydx = [3*a-2*z; % da/dx = 3a - 2z
a^2]; % dz/dx = a^2
end
function res = bc(ya, yb)
% Boundary conditions
% a(0) = 1,
% a'(1) = 0,
% z(1) = 2,
res = [ya(1) - 1; % a(0) = 1, Dirichlet condition for a at x=0
yb(1); % a'(1) = 0, Neumann condition for a at x=1
yb(2) - 2]; % z(1) = 2, Dirichlet condition for z at x=1
end
function g = guess(x)
% Initial guesses for y and z
g = [0;
0];
end

Antworten (1)

Torsten
Torsten am 16 Apr. 2024
Bearbeitet: Torsten am 16 Apr. 2024
Is there a possibility that I can set three boundaries (mix between Drichlet and Neumann boundary) for a set of two ODE's?
No. A first-order ODE (as the one for "a" in your code) needs a value for "a" either at the left or the right end of your interval of integration. Prescribing a derivative at either end is not possible with bvp4c (and mathematically wrong).

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by