Skip to main content
1 of 2
Michael E2
  • 258.7k
  • 21
  • 370
  • 830

On the borderline of comment and answer:

I've found it helpful to read the error messages carefully. They contain important information specific to your problem. These are telling you that b x+a x^2+c[T] is not a number when a number is substituted for x. In particular, a and b are nonnumeric symbols. It's complicated why the symbol T is present -- it certainly suggests that ?NumericQ might have failed (it didn't) -- so skip that for now. It's enough to notice that the integral is being called on nonnumeric a and b. Evidently, they, too, need to be protected by ?NumericQ.

To do that, you need to make the model and the user functions it calls depend on all the variables and parameters, including a and b. (See Öskå's answer.) One of the trickier things in programming to understand is the scope of symbols. In this case, the issue is that global symbols and function parameters with the same name are in fact different. Even experienced programmers are tempted to use a global symbol instead of a parameter -- who wants to type all those function arguments every time? But it is a bug waiting to happen. Maybe it will, maybe it won't. An experienced programmer can often predict when it is safe, but the bug is still lurking. In your case, the main culprit is y, which contains the global symbols a, b, c and T. (Again see Öskå's answer.) Now the T shows up in the error message because of this. In the OP's definition of z, T is a parameter. Its value is substituted for any symbol T that appears in the unevaluated right-hand side NIntegrate[y, {x, 0, X}]. But there are no T in the RHS. After parameter substitution, the RHS is evaluated and then y is evaluated. The T shows up at that time, too late for the substitution.

The advice about explicitly including all symbols on which a function depends as arguments of the function has been given many times by many people. The one I remember best is Issue with scope of variables

Michael E2
  • 258.7k
  • 21
  • 370
  • 830