Sei sulla pagina 1di 2

# Question

## 3: Charging a capacitor Question 3: Charging a capacitor

Write a function that calculates the evolution of the voltage and
current in this circuit.

## def simulate_circuit(V0, R, C, stop, ts):

t = 0
Vc = 0
simulation = []
while Vc <= stop*V0:
Equations: t += ts
Vc = V0*(1-exp(-t/(R*C)))
I = V0/R*exp(-t/(R*C))
*+ simulation.append([t, I, Vc])
!" = !% ∗ 1 − ) ,- return simulation

!% *+
.= ∗ ) ,-
/

## Question 3: Charging a capacitor Question 4: Sieve of Eratosthenes

Save out your nested list in a csv file. In this file, each line contains Write a function find_primes(a) that prints out all prime
the information of the simulation at a moment in time, separated numbers between 2 and a given number a.
by a semicolon “;”.
def find_primes(a):
numbers = range(2, a + 1)
def write_simulation(simulation, path):
file = open(path, 'w')
message = ''
for i in range(len(numbers)):
for measure in simulation: if mask[i] == 1:
message += str(measure) + ';' + str(measure) + ';' + str(measure)
message += '\n'
file.write(message)
multiples = numbers[i] ** 2
file.close() while multiples <= a:
multiples += numbers[i]

for i in range(len(numbers)):
print(numbers[i])
Question 4: Sieve of Eratosthenes
Write a function find_primes(a) that prints out all prime
numbers between 2 and a given number a.

def find_primes(a):

A
numbers = range(2, a + 1)

for i in range(len(numbers)):