I have the following:


b3b = 2;
G = (1/eps^2);
a1 = 3;
a3 = 4;
xc = 0.3;


y[x_] := (x*a1 - x^3*a3)/G
n[x_] := (y[x]^2)

I want g[x], gp[x], gpp[x] as functions of eps only and all of these three functions should be evaluated at x=xc :

g[x_] := (G*(-y[x]/eps)*Exp[-n[x]] - (b3b/eps)*
     NIntegrate[(y[s])^4*Exp[-n[s]], {s, 0, xc}])

Please note that in the integrand above --> both n[x] and y[x] are functions of eps and so I can use NIntegrate since I am using := for g[x] even though eps is not given a numerical value as yet. Everything is perfect till this point as I am able to get a numerical value for g[xc] for a eps value. The problem happens when I take the following derivatives:

 gp[x_] := D[g[x], x]
 gpp[x_] := D[gp[x], x]

since when I evaluate gp[xc] and gpp[xc] for a particular eps value, I get errors: NIntegrate::inumr and General::ivar.

Therefore, I need a way to get around this. I must be doing something wrong. Any help would be greatly appreciated. Thanks!

  • $\begingroup$ @Nasser If I use the := for g[x] then isn't it fine to use NIntegrate? because at the end I have to plot a huge function that requires g[xc], gp[xc], gpp[xc] to be changing with eps..i tried the one you had up and got General::ivar can you please tell me what I can do? $\endgroup$ – Stoc Aug 24 '13 at 23:53
  • $\begingroup$ @Nasser thanks for the help...apologies regarding that...can you please tell me what else I can do for my situation...can i use Integrate for g[x] instead and then take the derivatives? however, i still get an error when I evaluate the functions at x=xc for a particular eps...please help me as to what I can do $\endgroup$ – Stoc Aug 25 '13 at 0:02
  • $\begingroup$ @Nasser i guess they didn't read your post...please help me $\endgroup$ – Stoc Aug 25 '13 at 0:04
  • $\begingroup$ @Artes I reformulated the question as you suggested...can you please take a look now...i hope it makes more sense as to what I want to do now $\endgroup$ – Stoc Aug 25 '13 at 0:18

The problem here is the way you defined the derivatives. Mma will evaluate e.g. in this order: gp[xc] -> D[g[xc], xc] and obviously you'll get an error there. You may define the derivatives like this:

gp[x_] := D[g[t], t] /. t -> x
gpp[x_] := D[g[t], {t, 2}] /. t -> x

And you'll get it working:

Block[{eps = 0.1}, {gp[xc], gpp[xc]}]

{-19.1964, 72.004}
  • $\begingroup$ you are amazing...thanks so much for this..been dying for this! $\endgroup$ – Stoc Aug 25 '13 at 3:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.