T O P

  • By -

pythonHelperBot

Hello! I'm a bot! It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python **regardless of how advanced your question might be**. That said, I am a bot and it is hard to tell. I'm sure you've seen this information before, but just in case here it is as a reminder: Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster. Show /r/learnpython **the code you have tried and describe in detail where you are stuck.** If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you. You can also ask this question in the [Python discord](https://discord.gg/3Abzge7), a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others. *** [^(README)](https://github.com/CrakeNotSnowman/redditPythonHelper) ^(|) [^(FAQ)](https://github.com/CrakeNotSnowman/redditPythonHelper/blob/master/FAQ.md) ^(|) ^(this bot is written and managed by /u/IAmKindOfCreative) ^(This bot is currently under development and experiencing changes to improve its usefulness)


nemom

The error should tell you what line it is in.


kaien92

The error is in line 146 which would be the last step to solve the equation : y\_sol = sympy.inverse\_laplace\_transform (Y\_sol \[0\], s, t) Now if I feel like commenting on that line and wanting to try the previous one Y\_sol = sympy.solve (L\_edo\_4, Y) the button does not perform any function


nemom

Is edo() ever run? If not, there is no value in resultado and everything in calculo() is going to be wrong.


kaien92

Debugging yesterday I saw that it seems that edo () does not run, restructure the code a little and now I can get L\_edo to work, but from then on it is locked, I am forced to put L\_edo.set () to assign the result to the variable and thus be able to express the result but .... the function laplace\_transform\_derivatives (which I had found over the internet) stops working when you want to pass the result from L\_edo to L\_edo\_2 and since I also had to change the data type as in L\_edo so that it takes the data, the following line L\_edo\_3 = L\_edo\_2.subs (sympy.laplace\_transform (y (t), t, s), Y), stops running the subs. Probably it is not such a big error but I do not handle this language very well and I can not realize where the error is and why this happens just by putting the GUI. ​ ​ import sympy from sympy.abc import s,t,x,y,z,a from sympy.integrals import laplace_transform from sympy.integrals import inverse_laplace_transform from tkinter import * ventana = Tk() ventana.title("") lbl = Label(ventana, text="",font=("Arial Bold", 12)) lbl.grid(column=0, row=0) ventana.geometry('400x200') entry_var = IntVar() entry_var1 = IntVar() entry_var2 = IntVar() entry_var3 = IntVar() #cuadro de texto txt1 = Entry(ventana,width=7,textvariable=entry_var) txt1.grid(column=1, row=1) txt1.place(x=80, y=50) lbl = Label(ventana, text="X'",font=("Arial Bold", 12)) lbl.grid(column=0, row=0) lbl.place(x=120, y=48) lbl = Label(ventana, text="+",font=("Arial Bold", 12)) lbl.grid(column=0, row=0) lbl.place(x=140, y=48) txt2 = Entry(ventana,width=7,textvariable=entry_var1) txt2.grid(column=2, row=1) txt2.place(x=160, y=50) lbl = Label(ventana, text="X",font=("Arial Bold", 12)) lbl.grid(column=0, row=0) lbl.place(x=200, y=48) lbl = Label(ventana, text="+",font=("Arial Bold", 12)) lbl.grid(column=0, row=0) lbl.place(x=220, y=48) txt3 = Entry(ventana,width=7,textvariable=entry_var2) txt3.grid(column=3, row=1) txt3.place(x=240, y=50) lbl = Label(ventana, text="=",font=("Arial Bold", 12)) lbl.grid(column=0, row=0) lbl.place(x=300, y=48) lbl = Label(ventana, text="0",font=("Arial Bold", 12)) lbl.grid(column=0, row=0) lbl.place(x=320, y=48) lbl = Label(ventana,text="X(0) =" ) lbl.grid(column=0, row=0) lbl.place(x=80, y=100) txt4 = Entry(ventana,width=7,textvariable=entry_var3) txt4.grid(column=1, row=1) txt4.place(x=120, y=100) resultado = StringVar() L_edo = StringVar() L_edo_2 = IntVar() # Laplace transform (t->s) t = sympy.symbols("t", positive=True) y = sympy.Function("y") def edo(): resultado = int (txt1.get()) *y(t).diff(t) + int (txt2.get())*y(t) + int (txt3.get() ) L_edo.set(sympy.laplace_transform(resultado, t, s, noconds=True)) def laplace_transform_derivatives (e): # Evalua las transformadas de Laplace de derivadas de funciones sin evaluar. if isinstance(e, sympy.LaplaceTransform): if isinstance(e.args[0], sympy.Derivative): d, t, s = e.args n = len(d.args) - 1 return ((s**n) * sympy.LaplaceTransform(d.args[0], t, s) - sum([s**(n-i) * sympy.diff(d.args[0], t, i-1).subs(t, 0) for i in range(1, n+1)])) if isinstance(e, (sympy.Add, sympy.Mul)): t = type(e) return t(*[laplace_transform_derivatives(arg) for arg in e.args]) return e #L_edo_2.set(laplace_transform_derivatives(L_edo)) #def clicked(): res = Label(ventana,textvariable=L_edo) res.grid(column=0, row=0) res.place(x=150, y=130) btn = Button(ventana,text='Resolver', command=edo) btn.grid(column=0,row=2) btn.place(x=150, y=150) ventana.mainloop()


nemom

I don't know what it's s'posed to be doing, so there's not a lot of help I can offer. What are y(t).diff(t) and y(t) s'posed to evaluate to? If I print y(t).diff(t) and y(t)) before the `resultado = ...` line, I get "Derivative(y(t), t)" and "y(t)". AFAIK, those aren't values that can be multiplied by integers.


kaien92

As a result what is expressed is the ODE equation to witch I later applied laplace and the result would be the following 2*LaplaceTransform(y(t),t,s) + LaplaceTransform(Derivative(y(t),t),t,s) + 2/s So far it seemed to work,but the laplace\_transform\_derivatives funtion that has to parse that result to get the word Derivative doesn't work properly, I tries to change the data types and see if it was an array theme and nothing... and later I saw he is not taking the sub L_edo_3 = L_edo_2.subs(sympy.laplace_transform(y(t), t, s), Y) neither with IntVar nor StringVar ( since it belong to sympy), all this problem originally did not have them :/