0

My task at university is to model the collision of two particles. One subtask is to calculate the minimal distance of the two particles in dependance of a constant b.

I have to vary the constants b and I wanted to do so by just applying the function below on the whole linspace. However, instead of an array of solutions, the function returns just one value.

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fsolve

#given constants
sigma = 1
eps = 0.5
n_b = 100
b_var = np.linspace(0,3,n_b)

E = 0.2

def U(r):
    return 4*eps*((sigma/r)**12 - (sigma/r)**6)

def r_min(b):

    F = lambda r: E*(1 - (b**2/r**2)) - U(r)
    return fsolve(F,1)[0]

print(r_min(b_var))
>>> 0.98549755197
DavidG
  • 24,279
  • 14
  • 89
  • 82
  • Function `r_min(b)` returns only one index of the array `return fsolve(F,1)[0]` how do you expect it to return an array? – anishtain4 May 08 '18 at 19:24
  • It is the same without the "[0]" just that the result comes as [0.98549755197]. – Philipp Weder May 08 '18 at 19:33
  • if I have understood well you want all the roots of a two dimensional function with respect to one of the dimensions. In that case `fsolve` does not do the job. Take a look at here: https://stackoverflow.com/questions/13088115/finding-the-roots-of-a-large-number-of-functions-with-one-variable – anishtain4 May 09 '18 at 00:17

0 Answers0