From: Shen on
I am trying to solve the first-order ordinary differential equation

dy/dx = -sqrt(2*M^2*(sqrt(1-2*y/M^2) - 1) + exp(y) - 1

with boundary conditions

y(0) = -2.84 + ln(M)
y(inf) = 0
y'(inf) = 0

When I use bvp4c to solve this, I get the error

"Unable to solve the collocation equations -- a singular Jacobian encountered"

What am I doing wrong? See here for my current code:

function mat4bvp
clear all; clc
M = 5;
% linspace(beginX,endX,#ofpoints)
solinit = bvpinit(linspace(0,1000,100),@mat4init,M);
sol = bvp4c(@mat4ode,@mat4bc,solinit);

xint = linspace(0,pi);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))
% axis([0 pi -1 1.1])
title('Eigenfunction of Mathieu''s equation.')
xlabel('x')
ylabel('solution y')
% ------------------------------------------------------------
function dydx = mat4ode(x,y,M)
dydx = [ y(2)
-sqrt(2*M^2*(sqrt(1-2*y(1)/M^2)-1)+exp(y(1))-1) ];
% 2nd order approximation:
% y(1)^2/(2*M^2) + 0.5*y(1)^2];
% ------------------------------------------------------------
function res = mat4bc(ya,yb,M)
% (1) is referring to original function
% (2) is referring to first derivative
% ya is at initial position a
% yb is at initial position b
res = [ yb(2)
yb(1)
ya(1)-(-2.84+log(M)) ];
% ------------------------------------------------------------
function yinit = mat4init(x)
yinit = [ -exp(-x) exp(-x)];