Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the following:

Constants:

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

Functions:

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!

share|improve this question
    
@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? –  Stoc Aug 24 '13 at 23:53
    
@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 –  Stoc Aug 25 '13 at 0:02
    
@Nasser i guess they didn't read your post...please help me –  Stoc Aug 25 '13 at 0:04
    
@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 –  Stoc Aug 25 '13 at 0:18

1 Answer 1

up vote 2 down vote accepted

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}
share|improve this answer
    
you are amazing...thanks so much for this..been dying for this! –  Stoc Aug 25 '13 at 3:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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