Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display() funktion python

I am doing this in PyCharm:

    import sympy as sp
    from IPython.display import display, Math

    h,r,T = sp.symbols('h r T') #hier Eure Variablennamen einsetzen
    variablen = [h,r,T]         #hier Eure Variablennamen einsetzen

    variablen_werte = [2.8,4.2,2.4]  
    fehler_werte = [0.3,0.2,0.1] 

    funktion = (h*r**2*sp.sqrt(T))

    fehler = 0
    fehlersymbole=[]
    ableitungen_quadr = []

    for var in variablen:
        d = sp.symbols('d' + var.name)        
        fehlersymbole.append(d)               
        partial = sp.diff(funktion, var) * d  
        ableitungen_quadr.append(partial**2)
        fehler = fehler + partial**2

    fehler_abs=sp.simplify(sp.sqrt(fehler))              
    fehler_rel=sp.simplify(sp.sqrt(fehler/funktion**2))  

    funktions_wert=sp.Subs(funktion,variablen,variablen_werte).doit() 
                                                                  
    err1=sp.Subs(fehler,variablen,variablen_werte).doit()             
    err2=sp.Subs(err1,fehlersymbole,fehler_werte).doit()

    print('Funktion:')
    display(Math("f="+sp.latex(funktion)))
    print('Messwerte:')
    for i in range(len(variablen)):
      display(Math(str(variablen[i])+'='+ str(variablen_werte[i])+'\pm '+ str(fehler_werte[i])))
    print('Absoluter Fehler:')
    display(Math(r'\Delta f='+sp.latex(fehler_abs).replace('d',r'\Delta ')))
    print('Relativer Fehler:')
    display(Math(r"\Delta f/f="+sp.latex(fehler_rel).replace('d',r'\Delta '))) 
    display(Math("f= %6.2f \pm %6.2f" %(funktions_wert,sp.sqrt(err2))))        
    display(Math("f= %6.2f \pm %6.1f %s" %(funktions_wert,sp.sqrt(err2)/funktions_wert*100," \%")))

I have a lot of other display() functions that i will show, but cant. But now I have a problem with the output. For each display() the output is: <IPython.core.display.Math object> But it should be: enter image description here

What i am doing wrong ? Should i change my PyCharm config ? and How ?

like image 829
srky Avatar asked Aug 24 '26 13:08

srky


1 Answers

PyCharm only supports command-line (text-only) input/output. The result you're expecting is images of formulas generated using the IPython/Jupyter Notebook. So try to open the notebook program if it's installed and pasting your code into that. Example:

enter image description here

like image 94
xjcl Avatar answered Aug 26 '26 03:08

xjcl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!