Hi Aaron, thank you for the reply.
The code I have in my notebook (I'm using google colab) is this now (at the
end of the post), but using w is not working anymore.
Anyway, if I move back to use the line w = 2 * sp.pi * 50 I still get a
unreadble result.
The result should be something like the nice wikipedia result I found
there:
https://it.wikipedia.org/wiki/Circuito_RC#Risposta_in_frequenza_del_circuito_RC
Is there a way to get the a readble result? (something like the following
latex)
{\displaystyle v_{C}(t)=v_{C}(0)e^{-{\frac {t}{\tau }}}+K\cos(\omega
t+\theta )}
The wikipedia result has tau=R*C, theta is an angle displacement, and K
don't know what is.
In the italian wikipedia there's this piece (I try to translate) that I
would like to reproduce in a notebook:
Let's see how does the RC circuit works with a sine wave. We can use
voltage Kirchhoff law:
{\displaystyle V_{0}\cos(\omega t)=R\cdot i(t)+v_{C}(t)}
we can rewrite the equation like:
{\displaystyle V_{0}\cos(\omega t)=RC{\frac {dv_{C}(t)}{dt}}+v_{C}(t)}
and then solve the differential equation with constant coefficients with a
known therm:
{\displaystyle {\frac {dv_{C}(t)}{dt}}+{\frac {1}{\tau }}v_{C}(t)={\frac
{V_{0}\cos(\omega t)}{\tau }}}
where \tau =RC is still the time constant of the circuit.
The general solution come from the sum of the associated homogeneous
solution:
v_{C}(t)=v_{C}(0)e^{-{\frac {t}{\tau }}}
and a particolar solution:
{\displaystyle K\cos(\omega t+\theta )\ }
where K is a constant. So:
{\displaystyle v_{C}(t)=v_{C}(0)e^{-{\frac {t}{\tau }}}+K\cos(\omega
t+\theta )}
---------------- MY CODE --------------------
# define the independent variable ‘t’
from sympy.abc import t
import sympy as sp
#w = 2 * sp.pi * 50
w = sp.symbols('omega')
# define dependent variable in symbol form
vc = sp.symbols('vc', cls=sp.Function)
C, R, vo = sp.symbols('C R vo')
cos = sp.cos
diffeq = vc(t).diff(t) + (1/(R*C))*vc(t) - (vo*cos(w*t)/(R*C))
res = sp.dsolve(diffeq, ics={vc(0): 0})
res
Il giorno lunedì 27 giugno 2022 alle 22:30:32 UTC+2 ... ha scritto:
> What's the original ODE you are trying to solve? The solution you give
> has symbols in it that aren't in your diffeq.
>
> One change I would recommend is to use sympy.pi instead of math.pi.
> math.pi is a float approximation to pi, whereas sympy.pi is pi
> exactly. Alternatively, you can use w = symbols('omega') if you want
> the solution to match the general text version.
>
> Aaron Meurer
>
> On Mon, Jun 27, 2022 at 2:14 PM FM
> >
> > Hi, I'm writing a notebook to reproduce what I can see in this wikipedia
> page:
> > https://it.wikipedia.org/wiki/Circuito_RC
> >
> > The problem is the CAP 4, I'm looking forward to get the result that
> follow that text:
> > dove K è una costante. Dunque: (latex folleow)
> > {\displaystyle v_{C}(t)=v_{C}(0)e^{-{\frac {t}{\tau }}}+K\cos(\omega
> t+\theta )}
> >
> > This is my code, running in a colab notebook:
> > # define the independent variable ‘t’
> > from sympy.abc import t
> > import sympy as sp
> > import math
> > w = 2 * math.pi * 50
> >
> > # define dependent variable in symbol form
> > vc = sp.symbols('vc', cls=sp.Function)
> > C, R, vo = sp.symbols('C R vo')
> > cos = sp.cos
> >
> > diffeq = vc(t).diff(t) + (1/(R*C))*vc(t) - (vo*cos(w*t)/(R*C))
> > res = sp.dsolve(diffeq, ics={vc(0): 0})
> >
> > res
> >
> > The result is really confused, compared to the nice wikipedia result.
> > Is there a way to get the same result? (follow the latex)
> >
> > {\displaystyle v_{C}(t)=v_{C}(0)e^{-{\frac {t}{\tau }}}+K\cos(\omega
> t+\theta )}
> >
> > Thanks so much
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/fd8664a4-dd89-4552-b587-1ed845b5df74n%40googlegroups.com.