Electromagnetics 01, Python Coding

1. ÆÄÀ̽㠿¶óÀÎ ÀÚ½À¼­

¤· Tutorials Point 'Learn Python': https://www.tutorialspoint.com/python/index.htm

2. ¿ÀǼҽº ÆÄÀ̽ã ÄÚµùÅø Online Python »ç¿ë¹ý

¤· https://www.online-python.com/ ¿¡ Á¢¼ÓÇÏ¿© ¼Ò½ºÄڵ带 À§Ã¢¿¡ copy

¤· [Run]¾ÆÀÌÄÜ Å¬¸¯

¤· ¾Æ·¡ â¿¡ µ¥ÀÌÅÍ ÀÔ·Â prompt°¡ Ç¥½ÃµÇ¸é Űº¸µå·Î µ¥ÀÌÅÍ ÀÔ·ÂÇÑ´Ù. Ãâ·ÂÀº °°Àº â¿¡ Ç¥½ÃµÈ´Ù.

¤· °á°ú¸¦ ¹®¼­(º¸°í¼­)¿¡ ºÙ¿© ³Ö±â

- ÇÏ´Üâ »ó´ÜÀÇ [Stop] ¾ÆÀÌÄÜ Å¬¸¯

- ÇÏ´Üâ ÁÂÃø ù¹øÂ° ¾ÆÀÌÄÜ  Å¬¸¯ÇÏ¿© °á°ú ÅØ½ºÆ®¸¦ Clipboard¿¡ »ðÀÔ

- °á°ú¸¦ »ðÀÔÇÏ·Á´Â ¹®¼­·Î À̵¿ÇÏ¿© »ðÀÔÀ§Ä¡¿¡ Ä¿¼­¸¦ À§Ä¡ ½ÃŲ´Ù.

- Űº¸µå¿¡¼­ Ctrl + V¸¦ ´©¸£¸é °á°ú ÅØ½ºÆ®°¡ ´ÙÀ½°ú °°ÀÌ ¹®¼­¿¡ »ðÀԵȴÙ. 

q1(C)=

10e-6

q2(C)=

20e-6

q3(C)=

30e-6

R12,R13(m) =

0.1 0.2

F1(N)= 247.190808*******

q1(C)=

 

Session Killed due to Timeout.

Press Enter to exit terminal

 

 

(Âü°í)

¤· »ó´Üâ(¼Ò½ºÄÚµåâ) »ó´Ü¿¡ ¹èÄ¡µÈ ¾ÆÀÌÄÜ ¸Þ´º ÀǹÌ

»ó´ÜÁÂÃø ¾ÆÀÌÄÜ 4°³: Open file From Disk, Save File to Disk, Undo, Redo

»ó´Ü¿ìÃø ¾ÆÀÌÄÜ 3°³: Change Theme, About Site, Settings

¤· ÇÏ´Üâ(ÀÔÃâ·Ââ) ÁÂÃø ¾ÆÀÌÄÜ ¸Þ´º 5°³ÀÇ ÀǹÌ

Copy to clipboard: Ãâ·Ââ ³»¿ëÀ» Ŭ¸³º¸µå¿¡ copy (´ÙÀ½¿¡ Ctrl+v·Î ¹®¼­¿¡ »ðÀÔ)

Download: Ãâ·Ââ ³»¿ëÀ» txt ÆÄÀÏ·Î ÄÄÇ»ÅÍ·Î ´Ù¿î·Îµå

Clear: Ãâ·Ââ ³»¿ë Áö¿ò

Smart terminal: >>>°¡ Ç¥½ÃµÇ°í interpreter ¸ðµå. Python¸¦ 1ÁÙ¾¿ ½ÇÇà. help(print)

   ¿Í °°ÀÌ help Ç¥½Ã

Expand/Collapse: Expand = Ãâ·Â⸸ Àüüȭ¸é¿¡ Ç¥½Ã, Collapse: À§Ã¢, ¾Æ·¡Ã¢ µ¿½ÃÇ¥½Ã

 

3. ÆÄÀ̽ã ÄÚµù½Ç½À

3.1 Example 1: Äð·ÕÀÇ ¹ýÄ¢

1) ¹®Á¦

Medium: air, ¥å0 = 8.854¡¿10-12 F/m

q1 = 10 ¥ìC, q2 = 20 ¥ìC, q2 = 30 ¥ìC

q1 at (x, y, z) = (10, 0, 0) cm

q2 at (20, 0, 0) cm

q3 at (30, 0, 0) cm

Find the electrostatic force magnitude F1 on q1.

(Solution)

 

2) ¼ö½Ä

q in C (coulomb)

R in m (meter)

¥å0 in F/m (farad per meter)

F in N (newton)

q1 = 10 ¥ìC = 10e-6 C

q2 = 20 ¥ìC = 20e-6 C

q3 = 30 ¥ìC = 30e-6 C

R12 = 20 - 10 = 10 cm = 0.1 m

R13 = 30 - 10 = 20 cm = 0.2 m

 

3) ÄÚµù

# EM-01-Python-Ex1: Coulomb's law

e0=8.853e-12;pi=3.141593

while True: # ¹«ÇÑ·çÇÁ. ÇÁ·Î±×·¥À» ÁßÁö½Ã۱â Àü±îÁö °è¼Ó ¼öÇà

  q1=float(input('q1(C)=')) # while ºí·Ï ¼Ò¼ÓµÈ ÇÁ·Î±×·¥ ÁÙÀº µ¿ÀÏ Ä­¸¸Å­ µé¿©¾²±â

  q2=float(input('q2(C)=')); q3=float(input('q3(C)='))  #¿©·¯ ÁÙ ÇÁ·Î±×·¥ ÁÙÀ» ; »ç¿ëÇÏ¿© ÇÑ ÁÙ¿¡

# Űº¸µå·Î ÀԷµǴ ¸ðµç ¹®ÀÚ´Â character·Î Ãë±Þ. floatÀ» »ç¿ëÇÏ¿© ½Ç¼öÇü º¯È¯

  r12,r13=map(float,input('R12,R13(m) =').split()) #2°³ µ¥ÀÌÅÍ ÇÑÁÙ¿¡ ÀÔ·Â. »çÀÌ¿¡ space

  f1=q1*q2/(4*pi*e0*r12**2) + q1*q3/(4*pi*e0*r13**2)

  print('F1(N)=',f1)

 

(Âü°í) Python¿¡¼­ comment

# This is a comment.

y=2*x+3 # A linear function

"""

This is a multi-line comment.

Comment starts.

Comment ends.

"""

'''

This is a multi-line comment.

Comment starts.

Comment ends.

'''

¿©·¯ÁÙ comment: Å« ÀοëºÎ(") ¶Ç´Â ÀÛÀº ÀοëºÎ(') 3°³·Î µÑ·¯ ½ÎÀÎ ºÎºÐ

 

4) ÄÚµå ¼öÇà°á°ú

q1(C)=

10e-6

q2(C)=

20e-6

q3(C)=

30e-6

R12,R13(m) =

0.1 0.2

F1(N)= 247.190808*******

q1(C)=** Process Stopped **

 

Press Enter to exit terminal

 

3.2 Example 2: ¹«ÇÑ ¼±Àü·ùÀÇ ÀÚ±âÀå °è»ê

1) ¹®Á¦

Medium: air, ¥ì0 = 8.854¡¿10-12 H/m

I = 1000 A (756 kV Ãʰí¾Ð ¼ÛÀü¼±)

r = 30 m (¼ÛÀü¼±°ú Áö¸é »çÀÌ °Å¸®)

Find the magnetic flux density B (G)

B in G (gauss), 1 G = 0.1 mT = 10-4 T, T (Tesla)

 

2) ¼ö½Ä

I in A

¥ì0 in H/m

r in m

B in T

 

3) ÄÚµù

# EM-01-Python-Ex2: Magnetic field of a line current

pi=3.141593; u0=4*pi*1e-7

while True:

  I=float(input('I(A)='))

  r=float(input('r(m)='))

  B=u0*I/(4*pi*r)*1e4

  print('B(G)=',B)

 

4) ÄÚµå ¼öÇà°á°ú

I(A)=

1000

r(m)=

30

B(G)= 0.033333333333333326

I(A)=** Process Stopped **

 

Press Enter to exit terminal

 

3.3 Example 3:

(Âü°í) Python¿¡¼­ º¹¼Ò¼ö ¿¬»ê

(Complex numbers in Python)

¤· Ç¥±â: 1+2j, 1.+1.j, 2j

¤· ÀԷ½à °ýÈ£ ¾øÀÌ 1+2j¿Í °°ÀÌ ÀÔ·Â

¤· Ãâ·Â½Ã °ýÈ£°¡ »ç¿ëµÊ (½Ç¼ö, Çã¼ö ¸ðµÎ ÀÖÀ» ¶§)

2j

(1+2j)

¤· ½Ç¼öºÎ¿Í Çã¼öºÎ´Â ½Ç¼ö ±ÔÄ¢À» µû¸§.

¤· º¹¼Ò¼ö ÁöÁ¤

    z=3+2j

  z=complex(3,2)

 

¤· º¹¼Ò¼ö ¿¬»ê

4Ä¢¿¬»ê: + - * / **

z1+z2, z1-z2, z1*z2, z1/z2

z1**2, pow(z, 2), z1**z2

z.real

z.imag

z.conjugate()

z=complex(x, y)

z=complex(2, 4)

z=complex(2) # z=2+0j

 

¤· º¹¼Ò¼ö ¶óÀ̺귯¸® ÇÔ¼ö

from cmath import *

exp(z), phase(z), abs(z), polar(z),rect(r, phi), log(z, [base]), log10(z), sqrt(z)

acos(z), asin(z), atan(z), cos(z), sin(z), tan(z)

acosh(z), asinh(z), atanh(z), cosh(z), sinh(z), tanh(z)

 

1) ¹®Á¦

º¹¼Ò¼ö z1°ú z2¸¦ ÀÔ·Â¹Þ¾Æ z3 = z1*z2, z4=z1/z2¸¦ ½Ç¼ö/Çã¼ö, Å©±â/À§»ó(radian)À¸·Î Ç¥½Ã

 

2) ¼ö½Ä

 

3) ÄÚµù

# EM-01-Python-Ex3: Complex calulation

from cmath import * # Use the complex math library in Python

while True:

  z1=complex(input('z1='))

  z2=complex(input('z2='))

  z3=z1*z2; z4=z1/z2

  zp3=polar(z3); zp4=polar(z4)

  print('z3=',z3,'z3(polar)=',zp3)

  print('z4=',z4, 'z4(polar)=',zp4)

 

4) ÄÚµå ¼öÇà°á°ú

z1=

1+2j

z2=

3+4j

z3= (-5+10j) z3(polar)= (11.180339887498949, 2.0344439357957027)

z4= (0.44+0.08j) z4(polar)= (0.4472135954999579, 0.17985349979247828)

z1=** Process Stopped **

 

Press Enter to exit terminal

 

3.4 Example 4: R, L, C serie circuit impedance

1) ¹®Á¦

R, L, C, f °¡ ÁÖ¾îÁø °æ¿ì RLC Á÷·Äȸ·Î¿Í RLC º´·Äȸ·ÎÀÇ ÀÓÇÇ´ø½º¸¦ °è»êÇ϶ó.

 

2) ¼ö½Ä

R in ¥Ø (Ohm)

L in H (Henry)

C in F (Farad)

¥ø in rad/s

f in Hz (Herz)

 

3) ÄÚµù

# EM-01-Python-Ex4: RLC series and parallel circuits

pi=3.141593

while True:

  R=float(input('R(ohm)='))

  L=float(input('L(uH)='))

  C=float(input('C(uF)='))

  f=float(input('f(Hz)='))

  w=2*pi*f

  Zs=complex(R, w*L*1e-6-1/(w*C*1e-6))

  Zp=1/complex(1/R, w*C*1e-6-1/(w*L*1e-6))

  print('Z(series)=', Zs)

  print('Z(parallel)=', Zp)

 

4) ÄÚµå ¼öÇà°á°ú

R(ohm)=

100

L(uH)=

20

C(uF)=

50

f(Hz)=

1e6

Z(series)= (100+125.66053690148915j)

Z(parallel)= (1.0132629437904996e-07-0.0031831791384774404j)

R(ohm)=** Process Stopped **

 

Press Enter to exit terminal