# Passing NDSolve through NIntegrate?

Posted 8 months ago
991 Views
|
7 Replies
|
4 Total Likes
|
 Hello everyone,I was wondering: is it possible to solve a differential equation over a certain domain using NDSolve and pass that solution through NIntegrate? Any suggestions would be greatly appreciated!Alex Attachments:
7 Replies
Sort By:
Posted 8 months ago
 Some problems with the codeh is a list, not a function. Need h = h /. slv // First And in the definition of B, h needs to be h[t].What is g? It is used in the definition of B but is not defined. Easy to spot since it is colored blue.
Posted 8 months ago
 Sorry about that! I updated the notebook.
Posted 8 months ago
 OK, I evaluated the updated notebook and there are no errors and there is no NIntegrate. So, I am confused. What are you trying to integrate?
Posted 8 months ago
 I updated it again; I am so sorry for the confusion! I am trying to solve h'[t] numerically using NDSolve, plug the resulting h[t] values into b(1-cg)h[t]/K + b(1-cg)g(1 - h[t]/K) - dh[t]/K and numerically integrate the resulting curve. Is this possible?Alex
Posted 8 months ago
 Hi Alex,Thanks for changing the filename this time. The code in testt.nb 16-06-35-484.nb works fine for me. Make sure you start from a clean kernel. The problem is with the plotting because NIntegrate will be called hundreds of times. You can speed up the integration like this B[u_?NumericQ] := NIntegrate[(1 - c*g)*h[t]/K + g*(1 - c*g)*(1 - h[t]/K) - (h[t])/K, {t, A, u}, Method -> {Automatic, "SymbolicProcessing" -> 0}] Then this is pretty fast Plot[Exp[B[u]], {u, 0, 250}] Looks like the integral starts diverging around x = 225. Please verify that the change to B to speed it up is not impacting accuracy.
Posted 8 months ago
 WOW I really did not think this would be possible. Thank you SO MUCH!!
Posted 8 months ago
 Hello again,I was told I should not ask this question via a new discussion, so I was wondering: do you know how I could avoid receiving an error in the attached code and how I might make the code run faster? I am trying to pass one NIntegrate solution through another and subsequently pass that resulting function through NIntegrate. The code is not only slow but also gives me an answer that I think is wrong.Alex Attachments:
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.