Forum: PC Hard- und Software Gnuplot rechnet falsch?


von Student (Gast)


Lesenswert?

Ich versuche mit Gnuplot eine Funktion zu plotten:

f(x) = (8/3)*(7*x**3 - 35*x**4 + 112*x**5 - 224*x**6 + 256*x**7 - 
128*x**8)

Mit Maxima sieht das so aus.


An der Stelle 0.5 sollte der Wert 0.5 sein.

-> Gnuplot liegt um 1/8 drunter. Was verpeile ich?

von Roland P. (pram)


Lesenswert?

Rundungsfehler?

evtl mal ein x^3 ausklammern

von Student (Gast)


Lesenswert?

gnuplot> f(x) = (8/3)*(7*(x**3) - 35*(x**4) + 112*(x**5) - 224*(x**6) + 
256*(x**7) - 128*(x**8))
gnuplot> print f(0.5)
0.375
gnuplot>

verstehe ich nicht. 3/8 sind zwar 0.375, aber es gibt keinen 
zusammenhang. und der andere faktor sollte sein 0.1875

von Student (Gast)


Lesenswert?

Der Bruch ist schuld:

7.5 My formulas (like 1/3) are giving me nonsense results! What's going 
on?

Gnuplot does integer, and not floating point, arithmetic on integer 
expressions. For example, the expression 1/3 evaluates to zero. If you 
want floating point expressions, supply trailing dots for your floating 
point numbers. Example:

gnuplot> print 1/3
                0
gnuplot> print 1./3.
                0.333333

This way of evaluating integer expressions is shared by both C and 
Fortran.

von Student (Gast)


Lesenswert?

Uh, dass das eine die Hälfte vom anderen ist hätte ich sehen müssen!

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.