Eine Funktion plotten

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
Basilius Sapientia
User
Beiträge: 46
Registriert: Freitag 5. September 2014, 22:34

Servus!

Ich habe diesen http://9gag.com/gag/a0LdAVB Link gefunden. Dort steht eine Formel:
fx=x**2+(y-(x**2)**(1/3))**2=1

Ich wollte dies dann plotten. Doch ich habe Schwierigkeiten damit. Kann mir bitte jemand erklären, wie ich dies plotte? Natürlich hier mein Versuch:

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt

x=np.linspace(0, 100, 1)
y=np.linspace(0, 100, 1)

plot(show)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
savefig("test.png")
show()
Vielen Dank im Voraus!
Sirius3
User
Beiträge: 17741
Registriert: Sonntag 21. Oktober 2012, 17:20

@Basilius Sapientia: Wo berechnest Du die Formel "fx=x**2+(y-(x**2)**(1/3))**2=1" und was meinst Du macht plot(show)?
Matplotlib hat eine große Sammlung an Beispielplots. Da findest Du sicher den für dich passenden.
Benutzeravatar
MagBen
User
Beiträge: 799
Registriert: Freitag 6. Juni 2014, 05:56
Wohnort: Bremen
Kontaktdaten:

So geht's:

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

# x-Werte
anzahl = 100
x=np.linspace(0, 1, anzahl) # linspace(von, bis, Anzahl)

# y-Werte
# Gleichung x**2+(y-(x**2)**(1/3))**2=1
# nach y aufgeloest:
y = np.sqrt(1-x**2) + x**(2./3.)

# Test:
np.testing.assert_array_almost_equal(x**2+(y-(x**2)**(1./3.))**2, np.ones((anzahl,)))

# Plotten
plt.figure() 
plt.plot(x,y)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.savefig("test.png")
plt.show()
a fool with a tool is still a fool, www.magben.de, YouTube
Üpsilon
User
Beiträge: 222
Registriert: Samstag 15. September 2012, 19:23

@Magben das ist jez aber auch nur die halbe Wahrheit. Bei der Wurzel musste schon auch +/- machen.
PS: Die angebotene Summe ist beachtlich.
Benutzeravatar
MagBen
User
Beiträge: 799
Registriert: Freitag 6. Juni 2014, 05:56
Wohnort: Bremen
Kontaktdaten:

Und so war's gemeint:
Bild

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

# x-Werte
anzahl = 1000
# linspace(von, bis, Anzahl)
x=np.linspace(-1, 1, anzahl)

# y-Werte
# Gleichung
# x**2+(y-(x**2)**(1/3))**2=1
# nach y aufgeloest:
y1 =  np.sqrt(1-x**2) + (x**2.)**(1./3.)
y2 = -np.sqrt(1-x**2) + (x**2.)**(1./3.)

# Test:
np.testing.assert_array_almost_equal(x**2+(y1-(x**2)**(1./3.))**2, np.ones((anzahl,)))
np.testing.assert_array_almost_equal(x**2+(y2-(x**2)**(1./3.))**2, np.ones((anzahl,)))

# Plotten
plt.figure() 
plt.plot(x,y1, "r", linewidth=3)
plt.plot(x,y2, "r", linewidth=3)
plt.title('About as simple as it gets, folks')
plt.xlim(-1.05,1.05)
plt.ylim(-1.05,1.55)
plt.savefig("herz.png")
plt.show()
a fool with a tool is still a fool, www.magben.de, YouTube
Antworten