MATLAB: How to solve this second order nonlinear differential equation

algorithmdifferential equationsnumerical calculation

Here is the differential equation:
A*y''=B*y+C*y^3+D*y^5;
Boundary condition: y(0) = constant(known); y'(0) = 0;
y'(end)+E*y(end) = 0.
I wanted to solve it in the numerical way with Matlab, and have tried the finite difference method to discretize the above differential equation and get:
(-3*y(0)+4*y(1)-y(2))/2/h = 0;
A*(y(i+1)-2*y(i)+y(i-1))/h^2 = B*y(i)+C*y(i)^3+D*y(i)^5;
(-3*y(I-2)-4*y(I-1)+3*y(I))/2/h+E*y(I) = 0.
I tried the quasi-Newton method to solve the equation set, but the given initial value (y(0) = constant(known)) could not be used. And the values changed with different pre-set initial values.
Is there another method to solve this problem?
P.S. : A,B,C,D and E have their own exact values and it related to a practical problem, but the values of these coefficients are in different order of magnitudes so I didn't put them on the questions. Also the boundary value y(0) is an exact number and for the same reason I replaced it with constant to make it simple.

Best Answer

function mat4bvp
xstart=0.0;
xend=...;
A=...;
B=...;
C=...;
D=...;
E=...;
solinit = bvpinit(linspace(xstart,xend,10),[0 0]);
sol = bvp4c(@(x,y)mat4ode(x,y,A,B,C,D),@(ya,yb)mat4bc(ya,yb,E),solinit);
% ------------------------------------------------------------

function dydx = mat4ode(x,y,A,B,C,D)
dydx = [ y(2)
(B*y(1)+C*y(1)^3+D*y(1)^5)/A ];
% ------------------------------------------------------------
function res = mat4bc(ya,yb,E)
res = [ ya(1)
yb(2)+E*yb(1)];
Best wishes
Torsten.