# Quadgk not working for potential convert from MATLAB to Julia?

**URL:** <https://discourse.julialang.org/t/quadgk-not-working-for-potential-convert-from-matlab-to-julia/40600>\
**Category:** New to Julia\
**Created:** [June 2, 2020, 8:34am UTC](https://discourse.julialang.org/t/quadgk-not-working-for-potential-convert-from-matlab-to-julia/40600 "2020-06-02T08:34:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbpatzer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbpatzer/32/15355_2.png) [@jbpatzer](https://discourse.julialang.org/u/jbpatzer)\
**Post date:** [June 2, 2020, 8:34am UTC](https://discourse.julialang.org/t/quadgk-not-working-for-potential-convert-from-matlab-to-julia/40600/1 "2020-06-02T08:34:41Z")

</div>

In MATLAB, _quadgk(@(s) (exp(-s.^2)-1)./s.^2,0,1)_ gives me 0.8615, consistent with the correct answer, 1 - 1/e -sqrt(pi) erf(1).

In Julia, _quadgk(s-\> exp(-s.^2-1.0)./s.^2,0.0,1.0)_ gives  
me

_ERROR: DomainError with 4.7733380679681323e-153:_  
_integrand produced Inf in the interval (0.0, 9.546676135936265e-153)_

which suggests that it’s getting very hung up about the behaviour near s=0, even though Gaussian quadrature isn’t meant to evaluate the integrand at s=0.

Of course, this isn’t the actual integral that I’m interested in, but it illustrates the point.

Am I missing something subtle here? I really want to try using Julia, but this is not a great start.

☹

---

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [June 2, 2020, 8:50am UTC](https://discourse.julialang.org/t/quadgk-not-working-for-potential-convert-from-matlab-to-julia/40600/2 "2020-06-02T08:50:00Z")

</div>

In general you might have to be careful about functions like that where you divide by zero. But in this case you just have a typo in your command…

---

<div class="post-metadata">

**Author:** ![jbpatzer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbpatzer/32/15355_2.png) [@jbpatzer](https://discourse.julialang.org/u/jbpatzer)\
**Post date:** [June 2, 2020, 8:56am UTC](https://discourse.julialang.org/t/quadgk-not-working-for-potential-convert-from-matlab-to-julia/40600/3 "2020-06-02T08:56:47Z")

</div>

O ffs. I’m such an idiot. Thanks.
