Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7 views
unlisted
ubuntu2204
Kernel: Python 3 (system-wide)
import sympy as sp import sympy.plotting as splt x = sp.Symbol('x')
K = 10 eq1 = (2*x)**2/(0.1-x)**2-0.0753 res = sp.solve([eq1], [x], prec = 20) print("Lösungen:") res
Lösungen:
[(-0.0159022832155449,), (0.0120650472484646,)]
x1=res[1][0] sp.re(x1)

0.0120650472484646\displaystyle 0.0120650472484646

c = 1.013E5 *0.21 / 8.314/(25+273.15)/1000 print("{:.06g} mol/L = {:.06g} mmol/L".format(c, c*1000))
0.00858191 mol/L = 8.58191 mmol/L

Grafische Lösung

plot1 = splt.plot(eq1)
plot2 = splt.plot(eq1, xlim=(-0.05,0.05), ylim=[-1,1], adaptive = False, nb_of_points=10000)

Gleichungssysteme aus mehreren Gleichungen

y = sp.Symbol('y') eq1 = x**2 + y**2 -1 eq2 = x+y
res = sp.solve([eq1, eq2], [x,y], prec = 20) print(res)

Man könnte die Resultate nun beispielsweise in Listen speichern (xx und yy) und und komplizierte Ausdrücke wie sqrt(2)/e in Fliesskommezahlen umzuwandeln (.evalf()).

xx = [] yy = [] for i in range(len(res)): xres = res[i][0] yres = res[i][1] xx.append(xres) yy.append(yres) print("Lösung ",i,":") print("x",i," = ",xres, " = ", xres.evalf()) print("y",i,"= ",yres, " = ", yres.evalf()) print("alle Werte für x:",xx) print("alle Werte für y:",yy)
<IPython.core.display.Javascript object>
# Code ausblenden from IPython.display import HTML HTML(''' <script> var code_shown = true; function code_toggle() { if (code_shown){ $('.input').hide('500'); $('#CodeToggleButton').html('Code einblenden'); } else { $('.input:not(:contains("code_toggle"))').show('500'); $('#CodeToggleButton').html('Code ausblenden'); } code_shown = !code_shown }; function output_text_toggle() { if (code_shown){ $('.output_text').hide('500'); $('#TextToggleButton').html('Text einblenden'); } else { $('.output_text').show('500'); $('#TextToggleButton').html('Text ausblenden'); } code_shown = !code_shown }; function output_png_toggle() { if (code_shown){ $('.output_png').hide('500'); $('#pngToggleButton').html('Diagramme einblenden'); } else { $('.output_png').show('500'); $('#pngToggleButton').html('Diagramme ausblenden'); } code_shown = !code_shown }; function show_HTML(){ $('.input:contains("code_toggle")').show('500'); }; $('div.input:contains("code_toggle")').hide('500'); </script> <button ID="CodeToggleButton" onclick="code_toggle()"> Code ein/aus </button> <button ID="TextToggleButton" onclick="output_text_toggle()"> Output-Text ein/aus </button> <button ID="pngToggleButton" onclick="output_png_toggle()"> Output-Bilder ein/aus </button> <button onclick="show_HTML()"> HTML Code </button> ''')
%%javascript $('.input').show()
<IPython.core.display.Javascript object>