Polynom rückwärts lösen (y ist gegeben)

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
boletus999
User
Beiträge: 25
Registriert: Dienstag 27. August 2013, 07:04

Hallo liebe Gemeinde,

ich habe folgendes Polynom:

y = 53.643*x**3 - 69.877*x**2 + 72.1*x - 5.8153

mit Hilfe der Cardanischen Formel habe ich die Nullstellen berechnet, oder hier in Python mit Sympy

Code: Alles auswählen

#!/usr/bin/env python

from __future__ import division
import sympy as sy
x, y, z, t = sy.symbols('x y z t')
k, m, n = sy.symbols('k m n', integer=True)
f, g, h = sy.symbols('f g h', cls=sy.Function)

print sy.solve(53.643*x**3 - 69.877*x**2 + 72.1*x - 5.8153, x)
Ausgabe ist das:
[0.0875918052106270,
0.607519273652539 - 0.931967757064949*I,
0.607519273652539 + 0.931967757064949*I]

Und nun stehe ich völlig auf dem Schlauch. :oops:
Ich habe eine Liste mit mir bekannten y
z.B y = [129.456, 45.894, 187.041, ... ] etc

wie löse ich in python für jedes gegebene y das Polynom, um x zu erhalten?? :K

Vielen lieben Dank
Theory is when you know everything but nothing works.
Practice is when everything works but no one knows why.
In my office, theory and practice are combined:
nothing works and no one knows why.
boletus999
User
Beiträge: 25
Registriert: Dienstag 27. August 2013, 07:04

so ich beantworte es selbst :lol: :lol:

bzw. habe ich meinen Fuß vom Schlauch genommen
Lösung:

Code: Alles auswählen

#!/usr/bin/env python

from __future__ import division
import sympy as sy
x, y, z, t = sy.symbols('x y z t')
k, m, n = sy.symbols('k m n', integer=True)
f, g, h = sy.symbols('f g h', cls=sy.Function)

y = [99.3, 45.894, 30.041]

for i in range(len(y)):
   print sy.solve(53.643*x**3 - 69.877*x**2 + 72.1*x - 5.8153 -float(y[i]), x)[0]
Weil nach bei sy.solve das Polynom auf "0" gesetzt wird, also -y
:wink:
Theory is when you know everything but nothing works.
Practice is when everything works but no one knows why.
In my office, theory and practice are combined:
nothing works and no one knows why.
BlackJack

@boletus999: Die Schleife ist so wie sie da steht in Python ein „anti pattern”. Das `i` wird doch gar nicht wirklich gebraucht und über die Elemente von `y` kann man *direkt* iterieren mit ``for y in ys:``. Da habe ich jetzt mal `y` in `ys` umbenannt, weil das etwas ungünstig ist für viele Werte einen Namen zu verwenden der eher zu einem Einzelwert passt.
boletus999
User
Beiträge: 25
Registriert: Dienstag 27. August 2013, 07:04

Jawoll Meiser!
ich habe mir leider diesen „anti pattern” Stil angewöhnt, da ich zu viel und zu oft über variable Listen-Ranges iteriere.
Blöde Angewohnheit.

So sieht es wahrlich besser aus:

Code: Alles auswählen

#!/usr/bin/env python

from __future__ import division
import sympy as sy
x, y, z, t = sy.symbols('x y z t')
k, m, n = sy.symbols('k m n', integer=True)
f, g, h = sy.symbols('f g h', cls=sy.Function)

ys = [99.3, 45.894, 30.041]

for y in ys:
   print sy.solve(53.643*x**3 - 69.877*x**2 + 72.1*x - 5.8153 -y, x)[0]

Theory is when you know everything but nothing works.
Practice is when everything works but no one knows why.
In my office, theory and practice are combined:
nothing works and no one knows why.
Antworten