I'm trying to solve the ODE below using Matlab's ode45:
$$\frac{dy}{dx}=\sqrt{A\cdot \sin(y) + B\cdot \cos(y)}$$
where $0\le x \le 1$.
The Matlab code is:
A = -2.45;
B = 2.50;
tspan = 0:0.01:1;
odefun = @(t,y) sqrt(A*sin(y) + B*cos(y));
[t,y] = ode45(odefun, [0 1], 0);
The constants $A$ and $B$ are chosen such that inside the square root it is always non-negative. The solution seems fine for most values of $x$, but for the last few points close to $x=1$ I get complex $y$ with very small imaginary parts. I then took the real or the absolute value of $y$, but then I would get negative value inside the square root.
Should I try other ODE solvers? Or is there anything else I could do to eliminate the complex solutions?

