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
testt.nb 16-06-35-484.nb (210 KB)
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
testt.nb 16-06-35-484.nb (210 KB)
Some problems with the code
h 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.
Sorry about that! I updated the notebook.
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?
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) - d*h[t]/K and numerically integrate the resulting curve. Is this possible?
Alex
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.
WOW I really did not think this would be possible. Thank you SO MUCH!!
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
test 1.nb (12.4 KB)