Minimization of many-variable function

Click For Summary

Discussion Overview

The discussion revolves around minimizing a function of many variables using Python, specifically focusing on issues related to code implementation and function definition. Participants are addressing problems encountered in the coding process and the mathematical formulation of the function to be minimized.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant describes their attempt to minimize a function using the SciPy library, but expresses uncertainty about the correctness of their function definition and the overall approach.
  • Another participant requests clarification on the specific function to be minimized and the necessary steps involved in the process.
  • A third participant points out potential coding errors, including NameErrors and issues with variable definitions, suggesting that the 'parameters' tuple needs to be passed correctly to the function.
  • Concerns are raised about the proper use of data from a table to define the function and the need to sum elements from another table before minimization.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the correct implementation of the function or the resolution of coding issues, indicating that multiple competing views and uncertainties remain.

Contextual Notes

Limitations include unclear definitions of variables and potential errors in the code that have not been fully resolved. The discussion also highlights dependencies on specific data structures and the mathematical formulation of the problem.

gaby287
Messages
14
Reaction score
0
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.

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})
 
Technology news on Phys.org
Perhaps you could tell us more about the function you want to minimize and the steps you need to take to do it.
 
gaby287 said:
I have some problems with my code

What are the symptoms of those problems?
 
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 definition is correct, because what I need to do sum the elements of other table whit that function and after that minimize the result.
 
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.
 

Similar threads

  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K