6

Here is the equation I'm trying to solve:

NIntegrate[1/(E^(1/(λ T)) - 1), {λ, 200, 220}] == 1000

T is the parameter I'm trying to work out. I tried to solve it with InverseFunction[] but it seemed not to work:

te[ii_] := InverseFunction[NIntegrate[1/(-1 + E^(1/(# λ))), {λ, 200, 220}] &][ii]
Evaluate[te[1000]]

What's wrong with my solution? How to correct it?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
xzczd
  • 65,995
  • 9
  • 163
  • 468

2 Answers2

11

You can use FindRoot :

func[T_?NumericQ] :=  NIntegrate[1/(E^(1/(\[Lambda] T)) - 1), {\[Lambda], 200, 220}]

sol = FindRoot[func[T] == 1000, {T, 0.1}]

(* {T -> 0.240468} *)

func[sol[[1, 2]]]

(* 1000. *)

FindRoot needs an initial guess for the unknown; you can get a rough estimate by plotting func for instance.

b.gates.you.know.what
  • 20,103
  • 2
  • 43
  • 84
9

Here's a slight improvement of b.gatessucks's answer, adding a (mostly effective) initial guess:

te[ii_?NumericQ, opts___] := (\[FormalCapitalT] /. First@FindRoot[
     NIntegrate[1/(E^(1/(λ \[FormalCapitalT])) - 1), {λ, 200, 220}] == ii,
         {\[FormalCapitalT], (0.5437727672315316 + ii (0.5440978395984463 + 
                             ii (0.12244298721801757 + (0.009523809523809525 + 
                             0.0002380952380952381 ii) ii)))/(476.1910924718744 +
                             ii (247.61910924718742 + ii (30. + ii)))}, 
            Evaluated -> False, opts])

Here's how I obtained the initial guess:

PadeApproximant[InverseSeries[
    Integrate[#, {λ, 200, 220}] & /@ 
      Normal[Series[1/(E^(1/(λ ii)) - 1), {ii, Infinity, 7}]] + O[ii, Infinity]^8],
                {ii, Infinity, 4}] // N // FullSimplify
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
  • Wow, what a advanced solution…Er, I wonder where I can find the introduction of Evaluated, I can't find it in the help, and, it seems that PadeApproximant here isn't necessary, why you choose it? – xzczd Aug 01 '12 at 11:42
  • The Evaluated option is indeed undocumented, but it has been discussed a lot on this site; search around. As for PadeApproximant[], it's for generating a rational function approximation; they tend to be more accurate than truncations of Taylor polynomials for the same amount of arithmetic operations. – J. M.'s missing motivation Aug 01 '12 at 12:05
  • For example this? OK, it's very interesting, now…I'm sorry! But I still can't understand the independent variable opts___ which I thought I would make it out after I knew the meaning of Evaluated… – xzczd Aug 01 '12 at 13:07
  • The opts is for the case where you need to pass options to FindRoot[]. Now that I think about it, I should have also made provisions for passing options to NIntegrate[]... maybe later. – J. M.'s missing motivation Aug 01 '12 at 13:19
  • So, here I can just remove it? (Trying…) ………er, it seems that the ?NumericQ and Evaluated(whether it's True or False) are both unnecessary now… – xzczd Aug 01 '12 at 13:36
  • Well, you can certainly do te[ii_?NumericQ] := (* stuff *) and remove the opts within the definition, but the Evaluated is necessary; try it for yourself. – J. M.'s missing motivation Aug 01 '12 at 13:50
  • Yeah, I've tried:te[ii_] := (FindRoot[ NIntegrate[ 1/(E^(1/(\[Lambda] \[FormalCapitalT])) - 1), {\[Lambda], 200, 220}] == ii, {\[FormalCapitalT], (0.5437727672315316 + ii (0.5440978395984463 + ii (0.12244298721801757 + (0.009523809523809525 + 0.0002380952380952381 ii) ii)))/(476.1910924718744 + ii (247.61910924718742 + ii (30. + ii)))}]); te[1000] My version of mathematica is 8.0.4. – xzczd Aug 01 '12 at 13:56
  • Are you sure? Try Remove[te] and execute your definition again, and try evaluating at some numerical argument. – J. M.'s missing motivation Aug 01 '12 at 13:59
  • Oh…I forget that te should be removed first 囧. Yeah, you are right, the Evaluated here is necessary. So, the Evaluated here stops the calculation of the expression with an unknown parameter, but why the ?NumericQ doesn't work? – xzczd Aug 01 '12 at 14:19
  • The _?NumericQ is defensive programming; even if you accidentally pass it something that is manifestly not a number, it won't foul up. – J. M.'s missing motivation Aug 01 '12 at 14:24
  • OK, this time I completely understand…I think. Thank you! – xzczd Aug 01 '12 at 15:24