Minimization of many-variable function

AI Thread Summary
The discussion revolves around a user learning Python and facing challenges in minimizing a function with multiple variables using SciPy's optimization tools. The user has provided code that attempts to define a function based on data from a text file and minimize the sum of differences between this function and another dataset. Key issues identified include NameErrors in the code, particularly with the 'parameters' tuple and the undefined index 'I'. The user seeks clarification on how to properly define the function and structure the minimization process, emphasizing the need to correctly reference the datasets involved in the calculations.
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 definiton 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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such -conda create -n <env_name> python=3.7 ipykernel jupyter I am assuming this is successful as I can activate this environment via the anaconda prompt and following command -conda activate <env_name> Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted...

Similar threads

Replies
16
Views
2K
Replies
6
Views
3K
Replies
3
Views
2K
Replies
15
Views
2K
Replies
7
Views
5K
Replies
2
Views
3K
Replies
1
Views
1K
Replies
1
Views
3K
Back
Top