title: I am trying to solve the following problem using python
body: <p>I am trying to write a code that finds the advanced stage uncertainty of a process given some variables, however my code isn't running properly and I could use some help. This is the problem I'm trying to solve:</p>
  <p><a href="https://i.stack.imgur.com/Lh2K6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lh2K6.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/bwAlC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bwAlC.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/0GQlO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0GQlO.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/gE7Yk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gE7Yk.png" alt="enter image description here" /></a></p>
  <p>I wrote the following code:</p>
  <pre><code>from scipy.stats import t
  from sympy import diff, Symbol
  from sympy.parsing.sympy_parser import parse_expr
  '''exp = input('Enter the expression to find the propagation of error: ')
  var = input('Enter the variables containing uncertainty seperated by spaces: ').split()
  rss = [float(v) for v in input('Enter the variables RSS as a value seperated by spaces (if its in %, multiply by mean): ').split()]
  num=[float(v) for v in input('Enter the number of measurements of each variable seperated by spaces: ').split()]
  values=[float(v) for v in input('Enter the mean of each variable seperated by spaces: ').split()]
  std=[float(v) for v in input('Enter the standard deviation of each variable seperated by spaces: ').split()]'''
  exp = 'p/(54.7*t)'
  var = ['p','t']
  rss = [22.5391,0.6]
  num=[20,10]
  values=[2253.91,560.4]
  std=[167.21,3]
  for i,j in zip(var, values):
      a=exp.replace(i, str(j))
      print(a)
  x=eval(a)
  print(x)
  b=[]
  s=[]
  sv=[]
  for i in range(len(rss)):
      temp=rss[i]/2
      b.append(temp)
  for i in range(len(var)):
      sp=std[i]/((num[i])**0.5)
      temp=num[i] -1
      s.append(sp)
      sv.append(temp)
  symb = {x:Symbol(x, real = True) for x in var}  
  val_table = {symb[x]:v for x, v in zip(var, values)}
  symb = {x:Symbol(x, real = True) for x in var}  
  val_table = {symb[x]:v for x, v in zip(var, values)}
  func = parse_expr(exp, symb)  
  derivatives = [diff(func, symb[x]) for x in var]
  print(derivatives)  
  error_s = (sum((u)*d.evalf(subs=val_table)**2 for u, d in zip(s, derivatives)))**0.5
  error_b = (sum((u)*d.evalf(subs=val_table)**2 for u, d in zip(b, derivatives)))**0.5
  print(error_s)
  print(error_b)
  vsk=[]
  vbk=[]
  for i in range(len(s)):
      v=((s[i])**4)/sv[i]
      vsk.append(v)
      s[i]=s[i]**2
  for i in range(len(b)):
      b[i]=b[i]**2
  sx=(sum(s))**0.5
  print('the random uncertainty is: ',sx)
  bx=(sum(b))**0.5
  print('The systematic uncertainty is: ',bx)
  cux=round((((sx)**2)+((bx)**2))**0.5,2)
  print('The combined standard uncertainty is: ',cux)
  den1=sum(vsk)
  den2=sum(vbk)
  v=round((((cux**2)**2)/(den1+den2)),0)
  print('The degrees of freedom is: ',v)
  tdist=t.ppf(1-((1-(95/100))/2), v)  
  ecu=tdist*cux
  print('The best estimate is:+/-',ecu)
  </code></pre>
  <p>I am getting 80 as a final answer instead of 0.0026 and I am unable to evaluate x; I think my mistake is with the derivative, I hope someone can help. Many Thanks!!</p>