MatLab solves BVP with only left-hand side boundaries (How?)
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!