Forum: PC-Programmierung Formel in phyton code


von Tester (Gast)


Lesenswert?


von Bernd (Gast)


Lesenswert?

Meine Glaskugel sagt, dass dein Problem vermutlich der Exponent ist.

Schau mal in der Doku von Python nach:

https://docs.python.org/3.6/library/math.html#module-math
>math.pow(x, y)
>Return x raised to the power y. Exceptional cases follow Annex ‘F’ of the
>C99 standard as far as possible. In particular, pow(1.0, x) and pow(x, 0.0)
>always return 1.0, even when x is a zero or a NaN. If both x and y are
>finite, x is negative, and y is not an integer then pow(x, y) is undefined,
>and raises ValueError.
>Unlike the built-in ** operator, math.pow() converts both its arguments to
>type float. Use ** or the built-in pow() function for computing exact
>integer powers.

von lks (Gast)


Lesenswert?

T = 1
h = 5
P = 3
p0 = P*(1-((0.0065*h)/(T+0.0065*h+273.15)))**(-5.257)

wobei P hier als Konstante angenommen wird. Könnte nach der Fromel aber 
auch eine Funktion o.ä. sein. Dafür lieferst du zu wenig Informationen.

von Daniel A. (daniel-a)


Lesenswert?

1
def seaLevelPressure(P,T,h):
2
  return P * ( 1.0 - ( 0.0065*h ) / ( T + 0.0065*h + 273.15 ) )**-5.257

von Tester (Gast)


Lesenswert?

Kann man das auch etwas eleganter lösen mit der pow Funktion? Daran 
hänge ich grad

von mh (Gast)


Lesenswert?

Klar, die Doku sagt: The two-argument form pow(x, y) is equivalent to 
using the power operator: x**y.

von Tester (Gast)


Lesenswert?

also

pow( P*(1-((0.0065*h)/(T+0.0065*h+273.15))),(-5.257)) ?

von Heiko G. (heikog)


Lesenswert?

Eleganter ist das aber auch nicht gerade, und man muss den 
Operatorenvorrang selbst berücksichtigen, also Exponentiation vor 
Multiplikation:

P * Pow(...

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.