MatLab solves BVP with only left-hand side boundaries (How?)

1 次查看(过去 30 天)
My code is working but I do not really understand the following.
My ode System consist of three first order ode's:
I dy/dx = z
II dz/dy = 2y + 3z
III dw/dx = 2y + z
I wrote the code and was trying to set right and left hand side boundaries to solve my system, therefore I was setting 6 boundaries in total.
However, it seems like that only 3 boundaries are enough to solve the system. How is this working? I thought each ode requies both left and right hand side boundary to be able to solve.
Best regards,
Thanh
clear all; close all; clc
% Define the initial guess for the solution
solinit = bvpinit(linspace(0, 1, 50), @initial_guess);
% Solve the BVP using bvp4c
sol = bvp4c(@odefun, @bcfun, solinit);
% Extract the solutions from the sol structure
x = sol.x;
y = sol.y(1, :);
z = sol.y(2, :);
w = sol.y(3, :);
% Plot the solutions for y(x), z(x), and w(x)
subplot(3, 1, 1);
plot(x, y);
xlabel('x');
ylabel('y(x)');
title('Solution of ODE for y(x)');
subplot(3, 1, 2);
plot(x, z);
xlabel('x');
ylabel('z(x)');
title('Solution of ODE for z(x)');
subplot(3, 1, 3);
plot(x, w);
xlabel('x');
ylabel('w(x)');
title('Solution of ODE for w(x)');
function dydx = odefun(x, y)
dydx = [ y(2);
2*y(1) - 3*y(2);
y(1)*2 + y(2)];
end
function res = bcfun(ya, yb)
res = [ya(1) - 1; ya(2) - 2; ya(3)];% - [yb(1) - 3; yb(2) - 4; yb(3) - 5] right hand side boundaries
end
function yinit = initial_guess(x)
yinit = [-2;0;0];
end

采纳的回答

Torsten
Torsten 2024-1-10
编辑:Torsten 2024-1-10
A system of odes needs as many boundary conditions as the sum of the degrees of its equations. Since all your equations are first-order odes, it needs 1 + 1 + 1 = 3 boundary conditions in total.
If you had a system of second-order odes, then you are right: it would need 2 + 2 + 2 = 6 boundary conditions.
If you only set left-hand side or right-hand side conditions, it's called an initial value problem (in contrast to a boundary value problem) and should be solved using ode45, e.g., a solver for initial value problems.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by