0

I want to compute integral(@(v)v^46*exp(-v^2),0,inf). Mathematically, it can be computed. However, when I run in matlab, it gives NaN. Is it a problem due to the precision of the computer? If yes, how can I fix it? I also try of changing inf to a big no, say from 10000,100000,1000000,... the values increase and then drop to a very small no close to 0.

In the extreme case, I need to compute integral(@(v)(v-a)^200*exp(-v^2),0,inf), so I admire any correction based on the last integral.

melpomene
  • 84,125
  • 8
  • 85
  • 148
will_cheuk
  • 379
  • 3
  • 12

1 Answers1

1

The underlying problem is that isn't possible to integrate to infinity by substituting the floating point inf number. The integral function is purely numeric.

q = integral(fun,xmin,xmax) numerically integrates function fun from xmin to xmax using global adaptive quadrature and default error tolerances.

You will need to use the symbolic toolbox, which manipulates symbol rather than floating point values as per this answer.

Mikhail
  • 7,749
  • 11
  • 62
  • 136
  • If you think that that answer solves the question, please flag the question as a duplicate. – Adriaan May 03 '18 at 09:47
  • 1
    @Adriaan I don't think its a duplicate because OP is using the wrong function, and has confused numeric integration with symbol manipulation. Possibly missing the `syms` command. – Mikhail May 03 '18 at 09:48
  • The one I suggest may have explicit result. How about integral(@(v)(v-a)^200*exp(-v^2),0,inf)? When using symbolic, how can I do it? It may not have explicit formula. Using the symbolic toolbox does not help. – will_cheuk May 03 '18 at 10:06
  • @will_cheuk you need to use the `int` command – Mikhail May 03 '18 at 10:09
  • I have tried. see below: syms u int(exp(-u*u)*(u-10)^46, u, 0, inf) ans = int(exp(-u^2)*(u - 10)^46, u, 0, Inf) – will_cheuk May 03 '18 at 10:23
  • Also, I have read the documentation for integral, the xmin and xmax can be infinity. – will_cheuk May 03 '18 at 10:25