How to avoid singularity (dividing by 0) when solving a differential equations system numerically

307 Views Asked by At

I have invented this differential equation system:

$\frac{\mathrm{d}x(t)}{\mathrm{d}t}x(t)=-y(t)\cos(t)\\ \frac{\mathrm{d}y(t)}{\mathrm{d}t}x(t)=\cos^2(t)\\ x(0)=1;\,y(0)=0.$

I know that the solution is $x(t)=\cos(t)$ and $y(t)=\sin(t)$, but let's suppose that we don't know it.

I don't care if it is or not possible to solve it analytically, I want to solve it numerically. The problem is that when $x(t)=0$ there is a singularity (we are dividing by 0) and none of the algorithms I tried work.

Can I perform a variable change to get rid of this problem? Is there any other way besides a variable change to solve numerically this system of differential equations?

Thank you! Marcos.