Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.3K Views
|
3 Replies
|
1 Total Like
View groups...
Share
Share this post:

NIntegrate with parameters in Block: Avoid error messages?

POSTED BY: Vladimir Ivanov
3 Replies

Alexey Popkov and Szabolcs Horvát, thanks for answers.

In fact, I do not need a symbolic pre-evaluations of the integral, so this method works well for me.

POSTED BY: Vladimir Ivanov

This is unrelated to Block. Everything is explained here: http://support.wolfram.com/kb/12502

POSTED BY: Szabolcs Horvát
Posted 8 years ago

This error message comes from symbolic pre-evaluation performed by the outer NIntegrate and has nothing related to Block. The best is to combine the two NIntegrate into one:

y = 1;
NIntegrate[E^(-x y z), {x, 0, 1}, {z, 0, 1}]

(* => 0.7965995998164899`  *)

If the latter isn't possible, a workaround is to disable symbolic preprocessing by turning the inner integral into a black-box function (but it can considerably slow down integration):

Clear[f]
f[x_Real, y_] := NIntegrate[E^(-x y z), {z, 0, 1}]
Block[{y = 1}, NIntegrate[f[x, y], {x, 0, y}]]

(* => 0.7965995992970549`  *)
POSTED BY: Alexey Popkov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard