0
$\begingroup$

I have a function that involves a numerical calculation:

h[v_]:=NIntegrate[f[x]*Log[p[x, v]], {x, -Infinity, Infinity}]

I need to visualize how well a bunch of other functions of v match h[v], so I'm doing a lot of this:

Plot[g1[v]-h[v],{v,0,2}]
Plot[g2[v]-h[v],{v,0,2}]
Plot[g3[v]-h[v],{v,0,2}]

Is there a good way to somehow record h[v] so that I'm not calculating it over and over and over for all those v's?

And I need to make plots on-the-fly as new functions get generated, so I can't put them all in a list together and do this:

{g1[v],g2[v],g3[v]}-h[v]
$\endgroup$
  • 2
    $\begingroup$ Interpolation ? $\endgroup$ – Michael E2 Apr 13 '16 at 3:18
  • $\begingroup$ FunctionsThatRememberValuesTheyHaveFound $\endgroup$ – chuy Apr 13 '16 at 13:05
  • $\begingroup$ @MichaelE2 Yes, I could code up an interpolation scheme, but I was hoping something a little more elegant and accurate was possible, perhaps even built in. $\endgroup$ – Jerry Guern Apr 13 '16 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.