Sympy-Funktionen in Scipy lösen (optimize.root)Python

Python-Programme
Guest
 Sympy-Funktionen in Scipy lösen (optimize.root)

Post by Guest »

Ich versuche, die Wurzeln mit der Root-Funktion in Scipy für in Sympy erstellte Funktionen/Variablen zu finden.
sympy:
AllEquations = [x1 - 5, y1 - 5, z1 - 5, ((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)**0.5 - 150, y2 - 100, z2, ((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)**0.5 - 150]

AllVariables = [x1, y1, z1, x2, y2, z2]

Das Folgende funktioniert in Scipy, wird aber manuell durchgeführt:
def equation(p):
x1, y1, z1, x2, y2, z2 = p
return x1 - 5, y1 - 5, z1 - 5, ((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)**0.5 - 150, y2 - 100, z2, ((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)**0.5 - 150

initial_guess = [5,5,5,100,100,0]

from scipy.optimize import root
sol = root(equation, initial_guess, method = 'lm")

>>>sol.x
array([ 5.00000000e+00, 5.00000000e+00, 5.00000000e+00, 1.20974135e+02,
1.00000000e+02, -2.00332805e-25])

Die Frage ist nun, wie kann ich das automatisieren? Die obige Gleichungsfunktion ist statisch und sollte dynamisch erstellt werden, da sich die Anzahl der Parameter und Funktionen kontinuierlich ändert.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post