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:


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

  • 2
    $\begingroup$ 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. $\endgroup$ – rhermans Aug 21 '19 at 13:23

The argument of NIntegrate has to be numeric.


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}]

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.

  • $\begingroup$ 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. $\endgroup$ – Michael E2 Aug 21 '19 at 14:02

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.