# LinearAlgebra.SingularException(2) when solving matrix equation which is solvable in Maple

**URL:** https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142
**Category:** General Usage
**Created:** [May 31, 2021, 3:54pm UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142 "2021-05-31T15:54:41Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![vikhes](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vikhes](https://discourse.julialang.org/u/vikhes)
#### Post date: [May 31, 2021, 3:54pm UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142/1 "2021-05-31T15:54:41Z")

</div>

Hi

I’m doing an assignment where I use my own implementation of Implicit Eulers with adaptive step size using error estimation. For this, I have made my own implementation of the Newton solver. In one ODE system, my numerical solver fails to solve the following matrix equation.

```julia
dRdt = [2.7347115660463565e46 1.4462465159832052e46 7.06637105328182e46; 5.469423132092713e46 2.8924930319664105e46 1.413274210656364e47; -3.658477011433253e48 -1.9347779478036194e48 -9.453339201714811e48]
R = [1.0026696232160644e47, 2.0053392464321287e47, -1.3413640444362068e49]

dRdt\R

```

This returns the error

ERROR: LoadError: LinearAlgebra.SingularException(2)

I have tried to solve the equation in Maple and it solves it without an issue (see image below)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/8/589b420199b69808162d1fdbd56a258d306692dc.png)

Does anyone know what is wrong?

---

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [May 31, 2021, 4:03pm UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142/2 "2021-05-31T16:03:02Z")

</div>

> [@vikhes](#):
>
> ```julia
> dRdt = [2.7347115660463565e46 1.4462465159832052e46 7.06637105328182e46; 5.469423132092713e46 2.8924930319664105e46 1.413274210656364e47; -3.658477011433253e48 -1.9347779478036194e48 -9.453339201714811e48]
> R = [1.0026696232160644e47, 2.0053392464321287e47, -1.3413640444362068e49]
> 
> dRdt\R
> 
> ```
> 
> This returns the error
> 
> ERROR: LoadError: LinearAlgebra.SingularException(2)
> 
> I have tried to solve the equation in Maple and it solves it without an issue (see image below)  
> ![image](https://global.discourse-cdn.com/julialang/original/3X/5/8/589b420199b69808162d1fdbd56a258d306692dc.png)
> 
> Does anyone know what is wrong?

The system is ill-conditioned

```julia
julia> dRdt = [2.7347115660463565e46 1.4462465159832052e46 7.06637105328182e46
               5.469423132092713e46 2.8924930319664105e46 1.413274210656364e47
              -3.658477011433253e48 -1.9347779478036194e48 -9.453339201714811e48];

julia> cond(dRdt)
2.885773849638737e32

```

---

<div class="post-metadata">

### Author: ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)
#### Post date: [May 31, 2021, 5:07pm UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142/3 "2021-05-31T17:07:35Z")

</div>

I would factor out 10^{46} from the system 😉

---

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [May 31, 2021, 5:11pm UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142/4 "2021-05-31T17:11:24Z")

</div>

I don’t think that will affect the condition number, will it?

```julia
julia> svdvals(dRdt)
3-element Vector{Float64}:
 1.0321007400020088e49
 1.432533639792516e33
 3.576512900105512e16

julia> svdvals(dRdt .* 1.0e-46)
3-element Vector{Float64}:
 1032.1007400020085
    1.2316027007572554e-13
    2.9065558295847953e-16

```

---

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [May 31, 2021, 5:15pm UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142/5 "2021-05-31T17:15:29Z")

</div>

I guess I should have looked at the results before I said that it wouldn’t affect the condition number. The condition number for the scaled matrix is on the order of 10^19 instead of 10^33 but it is still computationally singular.

---

<div class="post-metadata">

### Author: ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)
#### Post date: [May 31, 2021, 5:23pm UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142/7 "2021-05-31T17:23:28Z")

</div>

The condition number won’t change in infinite precision, but that’s not what we’re dealing with here. Anyhow, as @dmbates observes, 10^19 is still bad enough to make most solvers complain.

---

<div class="post-metadata">

### Author: ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)
#### Post date: [May 31, 2021, 5:27pm UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142/8 "2021-05-31T17:27:28Z")

</div>

Indeed, my bad. You probably only gain floating-point representation space.  
My guess is that Maple computes the solution analytically (relatively easy for 3x3).

---

<div class="post-metadata">

### Author: ![vikhes](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vikhes](https://discourse.julialang.org/u/vikhes)
#### Post date: [June 3, 2021, 7:24am UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142/9 "2021-06-03T07:24:23Z")

</div>

Thank you all for your answers they were very helpful to understand what was going on! I ended up tweaking the tolerances of my solver, which avoided that ill-conditioned system and solved the ODEs.
