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

조회 수: 1 (최근 30일)
Thanh Hoang
Thanh Hoang 2024년 1월 10일
편집: Torsten 2024년 1월 10일
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