# Why does sol[r][[1]] become r?

This is a follow up to this question. This answer is great it gives the correct solution and I can plot it, but I have a problem: when I try to integrate the solution in this way:

NIntegrate[(sol[r][[1]]/.{t->t0})r^2,{r,10^7,10^8}]


whith $$t_0$$ fixed, the solution obtained before is somehow lost and I have sol[r][[1]]=r. How can I integrate sol[r][[1]]?

Maybe I should add that I integrate in a different cell

• I don't think it's reasonable to expect people will follow your links to dig out the value of sol. Link's are OK for further context, leave them in, but please edit you question to make it as self contained as possible. Ideally a simple copy&paste should be enough to reproduce your problem. – rhermans Aug 21 at 13:23

## 2 Answers

The argument of NIntegrate has to be numeric.

Try

sol = ParametricNDSolveValue[{eq, ic}, {\[CapitalSigma] , h, T}, {t,0, t0}, {r}]
(* without "[t]" *)

f[r_?NumericQ] := sol[r][[1]][t0] r^2 (*integrand*)
NIntegrate [f[r], {r, 10^4, 10^5}]
(*0.0281089*)


Answering the question in the title, which seems only tangentially related to the question in the body.

The expression sol[r][[1]] is equivalent to Part[sol[r], 1]. It wants the first part of sol[r]. If sol[r] evaluates to something like {a, b, c}, then the first part would be a. If it does not evaluate, then the first part of sol[r] is r, and that is what is returned.

• It's always a dilemma, whether to answer the question asked or address what you perceive is the OP's true desire. (+1) -- If you wanted to address the other question, you might suggest Indexed to replace Part. – Michael E2 Aug 21 at 14:02