Questions tagged [scipy-optimize]

Tag used for questions regarding minimizing or maximizing objective functions with python module `scipy.optimize`. Also add more generic tags to your question (`python`, `scipy`)

Module SciPy optimize is used for minimizing (or maximizing) objective functions. It includes solvers for nonlinear problems, linear programming, constrained and nonlinear least-squares, root finding and curve fitting.

1017 questions
2
votes
1 answer

Find maxima for a negative parabolic equation

I have the following negative quadratic equation -0.03402645959398278x^{2}+156.003469x-178794.025 I want to know if there is a straight way (using numpy/scipy libraries or any other) to get the value of x when the slope of the derivative is zero…
AGH
  • 300
  • 3
  • 12
2
votes
0 answers

Issue with scipy minimizer and equation

I am trying to minimize a simple equation with sklearn minimizer but, weirdly, it seems the minimizer does not even try and send me back really bad result. The equation has two different variable that I'd like to optimize for the formula to be…
natm
  • 21
  • 1
2
votes
1 answer

Failing a simple Cosine fit in Python

Here's how I generate my data and the tried fit: import matplotlib.pyplot as plt from scipy import optimize import numpy as np def f(t,a,b): return a*np.cos(b*t) v = 0 x = 0.03 t = 0 dt = 0.001 time = [] pos = [] while t<3: a =…
user929304
  • 465
  • 1
  • 5
  • 21
2
votes
0 answers

Importing SciPy in Python 3.9.1 yields zsh: bus error; Apple Silicon M1 Mac OS 11

I recently purchased new Mac Pro w/ Mac Os X 11.0.1 & Apple Silicon M1. I installed homebrew (when enabling Rosetta) and managed to install python3.9 and other packages through brew (numpy==1.19.5 & scipy==1.6.0, amongst others). However, executing…
Mietek
  • 21
  • 2
2
votes
1 answer

Python: How do I fit a line to a specific interval of data?

I am trying to fit a line to the 9.0 to 10.0 um regime of my data set. Here is my plot: Unfortunately, it's a scatter plot with the x values not being indexed from small numbers to large numbers so I can't just apply the optimize.curve_fit function…
Solveig
  • 35
  • 9
2
votes
0 answers

Minimizing Least Squares Subject To Constraint

I am trying to rate NFL teams by minimizing the sum of squared errors subject to a constraint. My data looks like: dat = {"Home_Team": ["KC Chiefs", "LA Chargers", "Baltimore Ravens"], "Away_Team": ["Houston Texans", "Miami Dolphins", "KC…
2
votes
1 answer

I am trying to fit periodic data to a template with scipy curve_fit but it doesn't find the period

I am trying to write a script that takes in photometry data of a potentially variable star and tries to fit a theoretical template to it to determine several characteristics about it such as period and amplitude. The data comes with a date/time (in…
Kyle
  • 21
  • 1
2
votes
1 answer

Minimum distance between atoms

I want to calculate the minimum distance between two atoms by means of the Lennard Jones potential. The formula I want to use is: V(r) = C12/r^12 - C6/r^6 where C12 = 1 and C6 = 10 The following construct of the function including variables was…
riejuhatza
  • 31
  • 2
2
votes
1 answer

Rayleigh distribution Curve_fit on python

I'm currently working on a lab report for Brownian Motion using this PDF equation with the intent of evaluating D: Brownian PDF equation And I am trying to curve_fit it to a histogram. However, whenever I plot my curve_fits, it's a line and does not…
2
votes
1 answer

Trouble solving a system of 6 nonlinear equations in Python

I'm trying to solve a system of 6 non linear equations with Python. So far I've got: from scipy.optimize import fsolve import math from numpy import log ka1 = 1.045 ka2 = 0.1759 ka3 = 0.3159 def equations(p): yh2o, yco2, yh2, ych4, yco = p …
2
votes
1 answer

Resolved: Alternative to using Global Variable in Numba

I am currently using scipy minimize for my optimization problem but the compute time is significant. I came across numba which could be used to reduce the compute time. But when i try to use it over my objective function, it throws the following…
2
votes
0 answers

scipy optimize trust-constr disobeyed linear constraints

I'm trying to use scipy.optimize.minimize with method trust-constr to optimize a function of 8 variables. Unfortunately, the function is too complicated to post in full here; it involves around 1000 terms, each of which involves an integral. But…
J.D.
  • 139
  • 4
  • 14
2
votes
0 answers

The difference between scipy.optimize.fsolve and sympy's solve functions

I am trying to figure out the differences between Optimize.fsolve and SymPys solve function? **Is there a difference in computation or are the constraints as to which method to use?**Is Scipy fsolve more accurate than Numpy solve function? The…
Mat
  • 45
  • 7
2
votes
1 answer

Cython: Workaround scipy.optimize.cython_optimize.brentq argument ctype to work with class methods ctype

I'm trying to use the root finder scipy.optimize.cython_optimize.brentq inside a class, but the first argument of this function accepts only the type ctypedef double (*callback_type)(double, void*) and my class method is the type of ctypedef double…
2
votes
1 answer

How to plot the progress of an optimization?

Is there a way to plot the progressive value of a function being optimized with scipy.optimize's differential evolution? In the following the plotting part doesn't work: from scipy.optimize import rosen, differential_evolution bounds = [(0, 5), (0,…
user2667847