Skip to content
Advertisement

Sweeping a parameter for an ODE function python

This isn’t an ODE question, per see. It’s more of a referencing issue, I think (but I might be wrong). I’ve copied the code below. I can’t seem to sweep parameters for an ODE function that I would like to run. Any advice/insight on how to fix this problem would be greatly appreciated! Thank you very much in advance!

CONTEXTUAL CODE:

JavaScript

When I test the sweep with two values for ‘pG1’ (they should give different outputs):

JavaScript

This outputs True. And it shouldn’t.

JavaScript

Advertisement

Answer

Based on my understanding you basically want to sweep the variable in this scenario pG1 through your ode. THe primary mistake is that the ODE is not accepting the values. odeint allows for odeint(model,model_init,t, args=(a,b,c)) according to the docs. Seeing as you are initializing the parameters globally, it doesnt actually work since the variable isn’t changed in the initial ode. I am not an expert at it but I got a working version with some changes to your code. Pretty sure there is a more elegant way of doing this which I hope someone can contribute.

JavaScript

This is definitely a hacky way to do it but it works. I am sure someone with more experience using odeint and the numpy/scipy package can give you an easier/cleaner way to do this. You can extend this for all the parameters if you so wish. I would not recommend globals however.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement