Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Minimization of many-variable function

  1. Oct 14, 2015 #1
    Hi, I'm learning python and I'm just trying to minimize a function of many variables, but I have some problems with my code.

    Code (Python):

    import numpy as np
    import scipy.optimize as op
    from scipy.optimize import minimize

    table1_np = np.genfromtxt('Data/tabla1.txt', usecols=0)
    def function(r0, rs):
          r0, rs = parameters
         return (r0*rs**3/table1_np[I])
    def function2(parameters):
          return sum(table2_np[I] - function[I])
               x0=np.array[0.7, 1.1]
          res=minimize(function2, x0, method = 'nelder-mead', options={'xtol':1e-8, 'disp':True})
  2. jcsd
  3. Oct 14, 2015 #2


    Staff: Mentor

    Perhaps you could tell us more about the function you want to minimize and the steps you need to take to do it.
  4. Oct 14, 2015 #3


    User Avatar

    Staff: Mentor

    What are the symptoms of those problems?
  5. Oct 15, 2015 #4
    Well I have a table of data (table1_np) and I want to use it to define a function, but the problem is, that I don't know if the definiton is correct, because what I need to do sum the elements of other table whit that function and after that minimize the result.
  6. Oct 15, 2015 #5


    User Avatar
    Gold Member

    There are some NameErrors in the code as you've likely seen. The tuple 'parameters' I believe you intend to be passed into the first function as it is the second function. Also the index name 'I', 'table2', etc.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook