analytic/euler/runge kutta solutions comparison problem

353 Views Asked by At

i've been trying to solve 1st order differential equations with dsolve, euler andy runge kutta methods and compare them on graphics. for simplification, dy means dy/dx: first equation is y' = exp(-2*x^2)-4*x*y with initial condition y(0) = -4.3 which i have no problem with. it plots as follows:

y' = exp(-2*x^2)-4*x*y

but using the same code, another diff. eq. plots with a huge error after the critical point. it is y' = (1-y^2)^.5 with initial condition y(0) = 1/sqrt(2)

y' = (1-y^2)^.5

here is my code: http://freetexthost.com/glmzxekwfd any help appreciated.

1

There are 1 best solutions below

0
On

The differential equation $$y'(x)=\sqrt{1-y^2(x)},\quad y(0)=1/\sqrt2,$$ is solved by $$y(x)=\left\{\begin{array}{ccc}\sin(x+\pi/4)&\text{if}&0\leqslant x\leqslant\pi/4\\1&\text{if}&x\gt\pi/4\end{array}\right.$$ The "analytik" curve in your figure seems to plot on the interval $(0,2)$ the function $z$ defined by $$z(x)=\sin(x+\pi/4),$$ which does not solve the differential equation on the interval $(\pi/4,2)$, since there, the graph of $z$ has a negative slope although the differential equation indicates that every solution $y$ is such that $y'(x)\geqslant0$ for every $x$. The function $z$ solves on the whole real line the differential equation $$(z'(x))^2=1-z^2(x),\quad z(0)=1/\sqrt2.$$ Another problem arises from the values greater than $1$ in the "euler" and "runge-kutta" plots. You are probably facing various bugs in the solvers you are using.