Created
March 2, 2013 23:33
-
-
Save Rhomboid/5073757 to your computer and use it in GitHub Desktop.
Capacitance equation solver with Sympy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sympy.parsing.sympy_parser import parse_expr | |
from sympy.solvers import solve | |
from itertools import zip_longest | |
def display_results(inputs, solutions): | |
columns = '{:25} {:25}'.format | |
print(columns('Input', 'Solutions'), | |
columns('-' * 25, '-' * 25), | |
*[columns(i, o) for i, o in zip_longest( | |
('{} = {}'.format(var, value) for var, value in sorted(inputs.items())), | |
('{} = {}'.format(var, value) for sol in solutions for var, value in sorted(sol.items())), | |
fillvalue='')], | |
sep='\n', end='\n\n') | |
def parallel_plate(**kwargs): | |
eqn = parse_expr('e_0*e_r*A/D - C') | |
vals = dict(e_0=8.85e-12, **kwargs) | |
solution = solve(eqn.subs(vals), dict=True) | |
display_results(vals, solution) | |
parallel_plate(A=0.01*0.01, e_r=1, D=0.001) | |
parallel_plate(C=1e-12, e_r=1, D=0.001) | |
parallel_plate(C=1e-12, D=0.001, A=0.01*0.1) | |
parallel_plate(C=1e-12, e_r=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Input Solutions | |
------------------------- ------------------------- | |
A = 0.0001 C = 8.85000000000000e-13 | |
D = 0.001 | |
e_0 = 8.85e-12 | |
e_r = 1 | |
Input Solutions | |
------------------------- ------------------------- | |
C = 1e-12 A = 0.000112994350282486 | |
D = 0.001 | |
e_0 = 8.85e-12 | |
e_r = 1 | |
Input Solutions | |
------------------------- ------------------------- | |
A = 0.001 e_r = 0.112994350282486 | |
C = 1e-12 | |
D = 0.001 | |
e_0 = 8.85e-12 | |
Input Solutions | |
------------------------- ------------------------- | |
C = 1e-12 A = 0.112994350282486*D | |
e_0 = 8.85e-12 | |
e_r = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment