I have an ODE such as the one below,


The analytical solution is clearly

$$y=C_{1}e^{ax} + C_{2}e^{-ax}$$

To apply boundary conditions $y(x=x_{1})=A$ and $y(x=x_{2})=B$, I recast into a matrix:

$\left( \begin{array}{ccc}e^{ax_{1}} & e^{-ax_{1}} \\ e^{ax_{2}} & e^{-ax_{2}} \end{array} \right)$$\left( \begin{array}{ccc}C_{1}\\ C_{2}\end{array} \right)=\left( \begin{array}{ccc}A\\ B\end{array} \right)$

My issue is that when $x_{1}$ and $x_{2}$ are far apart from one another (say $a=1,x_{1}=-10^{4},x_{2}=10^{4}$ or when $a$ is large (say $a=10^{4},x_{1}=-1,x_{2}=1$), the matrix inversion cannot be solved within machine precision. The issue is the exponential, which varies so widely. I was wondering what steps I could take to find the constants to satisfy my ODE solution.


Perhaps it might help to write the solution as

$$ y(x) = \frac{\sinh(a (x-x_2))}{\sinh(a (x_1 - x_2))} A - \frac{\sinh(a (x - x_1))}{\sinh(a (x_1 - x_2))} B$$

There will still be problems with overflow/underflow in numerical computation, though. Of course, when $t$ is large and positive, $\sinh(t) \sim e^t/2$, while when $t$ is large and negative, $\sinh(t) \sim -e^{-t}/2$. These can be used to get useful approximations in various regions.

  • $\begingroup$ This works, but I was wondering if there was a more robust method such as transforming my matrix into one with a better conditioning number. For example, dividing both sides of the equation $y(x=x_{1})=A$ would allow me to change the order of the first row. Similarly scaling the constant $C_{1}$ could allow me to scale the first column of the matrix. Is there a systematic algorithm I can use to implement such steps of rescaling? $\endgroup$ – Geoffrey Xiao Jul 13 '17 at 21:36
  • $\begingroup$ This is the exact solution. I don't see how you can do better. $\endgroup$ – Robert Israel Jul 13 '17 at 23:47
  • $\begingroup$ Search the topic of ill-conditioned matrices. There are iterative methods for solving $Ax=b$ when $\lambda_{max} / \lambda_{min}$ of the matrix $A$ is large. $\endgroup$ – player100 Jul 15 '17 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.