2
$\begingroup$

I have a function that is defined as the smallest root of a given polynomial. Something like this:

f[param1_,param2_,param3]:= Module[{roots}, roots = getRoots[param1,param2,param3]; Return[Min[roots]]; ] 

The function getRootswould build a polynomial and use Solve[] to solve it.

I need to integrate fnumerically, but I keep getting errors:

 NIntegrate::inumr: "The integrand Min[<<1>>] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,300000}}" 

Using Manipulate, I can calculate values along the integration range, that is, the function indeed has numerical values.

I suspect that the symbolic preprocessor tries to analyze the argument of Min[], but it get stuck because the argument is a list of roots of a polynomial.

Since the function f[]can be evaluated numerically, it should be possible to integrate it in a purely numerical way, without the symbolic analysis. Is there any way, any choice of integration method to do that?

$\endgroup$
3
  • 5
    $\begingroup$ Try NIntegrate[.., Method -> {Automatic, "SymbolicProcessing" -> False}] and define the function using f[param1_?NumericQ,param2_?NumericQ,param3_?NumericQ]:=...! $\endgroup$ Commented Oct 21, 2013 at 19:04
  • 1
    $\begingroup$ See also this pitfalls answer, and these q&a linked there: 1, 2, and less closely related 3. $\endgroup$ Commented Oct 23, 2013 at 0:39
  • $\begingroup$ Did you put a _ after param3 in your real code? As posted here, it seems it shouldn't work. Also, have you checked that e.g. f[1.,2.,3.] returns a number not some more complex expression? $\endgroup$ Commented Nov 21, 2013 at 10:36

1 Answer 1

1
$\begingroup$

Here is an example: let us take one equation, simple enough for a trial. Let it be

 Clear[x, y]; eq = y^5 - y^3 + x == 0; sl = Solve[eq, y] 

The result is:

(* {{y -> Root[x - #1^3 + #1^5 &, 1]}, {y -> Root[x - #1^3 + #1^5 &, 2]}, {y -> Root[x - #1^3 + #1^5 &, 3]}, {y -> Root[x - #1^3 + #1^5 &, 4]}, {y -> Root[x - #1^3 + #1^5 &, 5]}} *) 

The first of them, for example, is real at 0<=x<=1. Let us check it:

Plot[sl[[1, 1, 2]], {x, 0, 1}] 

Here it is shown:enter image description here

Now let us integrate:

NIntegrate[sl[[1, 1, 2]], {x, 0, 1}] 

The answer is:

(* -1.14189 *)

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.