Solving second degree ODE with bvp4c: error "The boundary condition function BCFUN should return a column vector of length 3."

Hello,
I am trying to solve a second degree boundary value problem. I followed the instructions on this page to use the solver bvp4c, but I get the error "The boundary condition function BCFUN should return a column vector of length 3.", which I don't understand, why should this system need 3 boundary conditions? Below are the derivation that I did, reproducing the reasoning of the bvp4c example, and a code that reproduce the error.
Thank you for you help!
Florian
%%%%%%%%%%%%%%% Parameters %%%%%%%%%%%%%%%
global y1 y2 theta lambda g dgdy
N = 10 ; % Number of mesh points
y1 = 0.0013 ; % Domain limits
y2 = 0.0017 ; %
y_range = linspace(y1, y2, N) ;
theta = 1 ;
lambda = 1 ;
g = @(lambda, y) - lambda ./ y ;
dgdy = @(lambda, y) lambda ./ y.^2 ;
%%%%%%%%%%%%%%% Resolution %%%%%%%%%%%%%%%
solinit = bvpinit(y_range, @guess) ;
sol = bvp4c(@odefun, @bcfun, solinit) ;
plot(sol.x, sol.y, '-o')
%%%%%%%%%%%%% ODE functions %%%%%%%%%%%%%
function dGdy = odefun(y, G)
global g dgdy lambda ;
dGdy = zeros(3,1) ;
dGdy(1) = G(2) ;
dGdy(2) = G(1) * g(lambda, y) ;
dGdy(3) = G(2) * g(lambda, y) + G(1) * dgdy(lambda, y) ;
end
function res = bcfun(Ga, Gb)
global y1 y2 theta
A = (1/y1 - theta/4) ;
B = (1/y2 - theta/4) ;
res = [Ga(2) - A * Ga(1) ;
Gb(2) - B * Gb(1)];
end
function G = guess(y)
global lambda y1 y2
G = [ cos( lambda * pi * (y-y1) / (y2-y1) ) ;
- (lambda * pi / (y2-y1)) * sin( lambda * pi * (y-y1) / (y2-y1) ) ;
- (lambda * pi / (y2-y1))^2 * cos( lambda * pi * (y-y1) / (y2-y1) ) ];
end

2 commentaires

... why should this system need 3 boundary conditions?
It only needs two boundary conditions (however it can have intermediate conditions as well). The boundary conditions need to be defined as a function of every differential equation in the system in ‘odefun’ (in the bvp4c documentation description, as well as your code as posted).
If the differential equation is actually second-degree (with a second derivative as the highest derivative), I suspect it is not coded correctly.
I'm not sure I understand what you mean. As you can see in the first system of equations, it is second degree. Are you saying that the variable change should make G_3 (i.e. the second derivative of my unknown function) appear in the boundary conditions?

Connectez-vous pour commenter.

Réponses (0)

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by