<filename>Prova 1/prova1-gc.py
# -*- coding: utf-8 -*-
"""Prova1.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1J4_EmjNOeP_JysmCfQXs2Vahl2we-DpE

# Prova 1 - O Paradoxo do Capacitor Gêmeo - <NAME> - BEC VII
"""

import matplotlib.pyplot as plt
from math import exp

r = float(input('Valor de R(ohms): '))
c = float(input('Valor de C(Farads): '))
v0 = float(input('Valor inicial da tensão no capacitor(Volts): '))

graphT = []
graphI = []
graphV = []
graphV1 = []
graphV2 = []

t0 = 0
i0 = 0
v10 = v0
v20 = 0

graphT.append(t0)
graphI.append(i0)
graphV1.append(v10)
graphV2.append(v20)
graphV.append(v0)

h = 0.1
n = 2.5/h

def v(t):
    return v0 * exp(-t*2/(r*c))

def i(t, i0):
    return i0 * exp(-t/(r*c*0.5))

def v1(v):
    return 0.5*(v0 + v)

def v2(v):
    return 0.5*(v0 - v)

while graphT[-1] < n:
    graphT.append(graphT[-1]+h)
    
    k1= i(graphT[-1], graphI[-1])
    k2= i(graphT[-1] + h/2, graphI[-1] + h/2)
    k3= i(graphT[-1] + h/2, graphI[-1]+ (h/2)*k2)
    k4= i(graphT[-1]+ h, graphI[-1]+ h*k3)

    graphI.append(graphI[-1] + (h/6)*(k1 + 2*k2 + 2*k3 + k4))

    graphV.append(v(graphT[-1]))
    graphV1.append(v1(graphV[-1]))
    graphV2.append(v2(graphV[-1]))

plt.plot(graphT,graphV1, label='v1(t)')
plt.plot(graphT,graphV2, label='v2(t)')
plt.plot(graphT,graphI, label='i(t)')
plt.plot(graphT,graphV, label='v(t)')
plt.legend()
plt.show()

"""**REFERÊNCIAS**

Aula 1 - Paradoxo dos Capacitores em Paralelo - https://www.dt.fee.unicamp.br/~www/ea513/node3.html

The Twin Capacitor Paradox - https://youtu.be/HlqC2cT7PcQ

Simução do Circuito - https://www.multisim.com/content/DdGp2NzXnAwEX9YDtyzfPE/prova-1-sistemas-e-sinais/
"""
<filename>Prova 1/prova1-gc.py
# -*- coding: utf-8 -*-
"""Prova1.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1J4_EmjNOeP_JysmCfQXs2Vahl2we-DpE

# Prova 1 - O Paradoxo do Capacitor Gêmeo - <NAME> - BEC VII
"""

import matplotlib.pyplot as plt
from math import exp

r = float(input('Valor de R(ohms): '))
c = float(input('Valor de C(Farads): '))
v0 = float(input('Valor inicial da tensão no capacitor(Volts): '))

graphT = []
graphI = []
graphV = []
graphV1 = []
graphV2 = []

t0 = 0
i0 = 0
v10 = v0
v20 = 0

graphT.append(t0)
graphI.append(i0)
graphV1.append(v10)
graphV2.append(v20)
graphV.append(v0)

h = 0.1
n = 2.5/h

def v(t):
    return v0 * exp(-t*2/(r*c))

def i(t, i0):
    return i0 * exp(-t/(r*c*0.5))

def v1(v):
    return 0.5*(v0 + v)

def v2(v):
    return 0.5*(v0 - v)

while graphT[-1] < n:
    graphT.append(graphT[-1]+h)
    
    k1= i(graphT[-1], graphI[-1])
    k2= i(graphT[-1] + h/2, graphI[-1] + h/2)
    k3= i(graphT[-1] + h/2, graphI[-1]+ (h/2)*k2)
    k4= i(graphT[-1]+ h, graphI[-1]+ h*k3)

    graphI.append(graphI[-1] + (h/6)*(k1 + 2*k2 + 2*k3 + k4))

    graphV.append(v(graphT[-1]))
    graphV1.append(v1(graphV[-1]))
    graphV2.append(v2(graphV[-1]))

plt.plot(graphT,graphV1, label='v1(t)')
plt.plot(graphT,graphV2, label='v2(t)')
plt.plot(graphT,graphI, label='i(t)')
plt.plot(graphT,graphV, label='v(t)')
plt.legend()
plt.show()

"""**REFERÊNCIAS**

Aula 1 - Paradoxo dos Capacitores em Paralelo - https://www.dt.fee.unicamp.br/~www/ea513/node3.html

The Twin Capacitor Paradox - https://youtu.be/HlqC2cT7PcQ

Simução do Circuito - https://www.multisim.com/content/DdGp2NzXnAwEX9YDtyzfPE/prova-1-sistemas-e-sinais/
"""
# -*- coding: utf-8 -*- Prova1.ipynb  Automatically generated by Colaboratory.  Original file is located at     https://colab.research.google.com/drive/1J4_EmjNOeP_JysmCfQXs2Vahl2we-DpE  # Prova 1 - O Paradoxo do Capacitor Gêmeo - <NAME> - BEC VII **REFERÊNCIAS**  Aula 1 - Paradoxo dos Capacitores em Paralelo - https://www.dt.fee.unicamp.br/~www/ea513/node3.html  The Twin Capacitor Paradox - https://youtu.be/HlqC2cT7PcQ  Simução do Circuito - https://www.multisim.com/content/DdGp2NzXnAwEX9YDtyzfPE/prova-1-sistemas-e-sinais/