Welcome to Mathematica.SE! I have formatted the question in the way that is customary on this site. You can click the EDIT link above to see how I did this so you can do it yourself next time. Also, can you please indicate what answers you are getting yourself, and (if necessary) explain why they are wrong? It might happen that the results are not the same on others' machines, so it is good practice to do this. Also, to make the code complete, provide the numerical value of Ttot (I know that this is just a small oversight).
–
SzabolcsOct 30 '13 at 20:41

Now in this case, I can see the problem on my machine. The derivative Mma computes, using g'[x], is clearly incorrect and it's negative where it should be positive. It may be because of the unusual magnitude of the numbers you used, but it's clearly incorrect on my machine. The ND function from the <<NumericalCalculus` package is usually much more reliable. However, in this case it also gives a wrong result on my machine! I do not know why. Looks like a bug to me.
–
SzabolcsOct 30 '13 at 20:43

2 Answers
2

It is a pain to see ND behave in a erratic manner for this example! However a quick fix is also within reach! We can use finite difference here. For more detail about this check here. In the code supplied by the OP I have assumed Ttot = 1.0.

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.