Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2075

Re: Replacements and NIntegrate

From DrMajorBob <btreat1@austin.rr.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Replacements and NIntegrate
Date 2011-05-04 10:32 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ipr9vs$qg$1@smc.vnet.net> (permalink)

Show all headers | View raw


You answered your own question, since

NIntegrate[ h[z] z / Sqrt[L^2 + z^2]  /.vals, {z, -L /.vals, L/.vals}]

does the replacements before trying to integrate.

Or, you could properly define h[z_,a_,b_....] as a function of its  
arguments and parameters and L[a_,b_, ...] as a function of ITS arguments,  
rather than leaving most of them out.

It's generally a good idea to define functions with ALL their dependencies  
obvious in the definition. It leads to less confusion.

Bobby

On Tue, 03 May 2011 04:44:43 -0500, Giacomo Ciani <jackspam79@gmail.com>  
wrote:

> Hi all,
>
> I've been reading quite a bit in the Mathematica docs and in this
> newsgroup, but didn't find (or didn't recognize...) an answer to my
> problem.
>
> I want to evaluate the following expression:
>
> NIntegrate[h[z] z/Sqrt[L^2 + z^2], {z, -L, L}]
>
> where h[z] has a delayed value set previously in the notebook. Also, I
> have previously defined a set of replacement rules in the form:
>
> vals = {a->1, b->2, ec....}
>
> to be used to specify the numerical values of the various parameters
> (including those present in the delayed value of h[z]).
>
> As for now, the only (brute force) way I found to have my expression
> correctly evaluated is to apply replacement rules separately to each
> argument of NIntegrate (including integration limits):
>
> NIntegrate[ h[z] z / Sqrt[L^2 + z^2]  /.vals, {z, -L /.vals, L/.vals}]
>
> I think you agree with me that this does not look very elegant.
> Instead, I would like to be able to write something like this:
>
> NIntegrate[h[z] z/Sqrt[L^2 + z^2], {z, -L, L}]/.vals
>
> I know this can't work, as Mathematica tries to evaluate NIntegrate
> and then apply the replacement rules... but how can I ask Mathematica
> to apply all the replacement rules and delayed values to an expression
> without (or before) actually trying to evaluate it?
>
> I found a lot of commands to hold the function from evaluating the
> arguments, while I need pretty much the opposite...
>
> Maybe there is something very simple I am overlooking...
>
> Thanks
>
> Giacomo
>


-- 
DrMajorBob@yahoo.com

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Replacements and NIntegrate DrMajorBob <btreat1@austin.rr.com> - 2011-05-04 10:32 +0000

csiph-web