-3

When you write a program with lots of code, its difficult to find out which values have a big influence of your final result. In my case i have got a few differential equations which I solve with odeint. It would take a lot of time to find out which values have a big influence on my result (velocity). Is there any Tool in python to analyze your values or does someone have any idea?

Thanks for your help.

[Edit]

MathBio: "In general a sensitivity analysis is what you would do. "

@MathBio I read a few blogs about SALib now(SALib Guide) and tried to write a "easier" test program to solve differential equations. Below you see my written program: I get the error-message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
    execfile(filename, namespace)
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "C:/Users/Tim_s/Desktop/Workspace/test/TrySALib.py", line 44, in <module>
    Y = Odefunk(param_values)
  File "C:/Users/Tim_s/Desktop/Workspace/test/TrySALib.py", line 24, in Odefunk
    dT=odeint(dTdt,T0,t,args=(P,))
  File "C:\Python27\lib\site-packages\scipy\integrate\odepack.py", line 148, in odeint
    ixpr, mxstep, mxhnil, mxordn, mxords)
  File "C:/Users/Tim_s/Desktop/Workspace/test/TrySALib.py", line 17, in dTdt
    dT[0]=P[0]*(T[1]-T[0])+P[2]
IndexError: tuple index out of range

Here the code:

from SALib.sample import saltelli
from SALib.analyze import sobol
import numpy as np
from pylab import *
from scipy.integrate import odeint


Tu=20.
t=linspace(0,180,90) 


def dTdt(T,t,P):# DGL
    dT=zeros(2)
    dT[0]=P[0]*(T[1]-T[0])+P[2]
    dT[1]=P[1]*(Tu-T[1])+P[0]*(T[0]-T[1])
    return dT

T0=[Tu,Tu]
def Odefunk(values):
    for P in enumerate(values):
        dT=odeint(dTdt,T0,t,args=(P,))
    return dT





# Define the model inputs
problem = {
    'num_vars': 3,
    'names': ['P0', 'P1', 'P2'],
    'bounds': [[ 0.1, 0.2],
               [ 0.01, 0.02],
               [ 0.5, 1]]
}

# Generate samples
param_values = saltelli.sample(problem, 1000, calc_second_order=True)

# Run model (example)
Y = Odefunk(param_values)

# Perform analysis
Si = sobol.analyze(problem, Y, print_to_console=False)

# Print the first-order sensitivity indices
print Si['S1']
qwertz
  • 619
  • 1
  • 7
  • 15

1 Answers1

1

You really should include your odes, so we can see the parameters and the initial condition. Code would be nice also.

In general a sensitivity analysis is what you would do. Performing a nondimentionalization is standard also. Look up these tips and try to implement them to see how varying a parameter a small amount will effect your solution.

I suggest you look up these concepts, and include your code. You should try the first steps yourself, and then I'd be happy to help with anything technical once you've clearly made an effort. Best wishes.

MathBio
  • 367
  • 1
  • 2
  • 13
  • Thank you.I tried to write a program with SALib. The code is above – qwertz Jan 21 '16 at 13:04
  • Hey sqwertz, I'm not familiar with the package SALib, but I can infer from your code roughly what it does. It seems in dTdt and Odefunk, you're passing an array P or referencing its values e.g. P[0]. The thing I'm confused about is how you pass an array with P0, P1, P2 into param_values, then into your parameter generator; does your code know how to associate P with the array 'names' in samples? Sorry for not reading the reference you provided, I just wanted to be sure the entries in 'names' were being associated to your parameter array P. – MathBio Jan 21 '16 at 14:59