<jupyter_start><jupyter_text>Task 1  The gravitational force between two masses at distance r is $F = G \\frac{m1m2}{r^2}$  The gravitational potential of a mass at some distance is  𝑉= G \\frac{m1}{r} ¶  The gravitational intensity of a mass at some distance $g = G \\frac{m1}{r^2}$<jupyter_code>class Gravitation():
    def __init__(self,G,m1,m2,r):
        self.G=G
        self.m1=m1
        self.m2=m2
        
    def Force(self,r):
        F=self.G*self.m1*self.m2/r**2
        return F
    def potential(self,r):
        V=self.G*self.m1/r
        return V
    def intensity(self,r):
        E=self.G*self.m1/r**2
        return E

G=6.67*10e-11
m1=5.57*10e-20 #in kg
m2=3.25*10e-17 #in kg
R=[] #empty list to collect distance r
F=[] #empty list to collect force F
V=[] #empty list to collect potential V
E=[] #empty list to collect intensity E
for r in range (1,3700): #for loop
    C1= Gravitation(G,m1,m2,r)
    f=C1.Force(r)
    v=C1.potential(r)
    e=C1.intensity(r)
    R.append(r)
    F.append(f)
    V.append(v)
    E.append(e)
    #print(r)
import matplotlib.pyplot as plt #plt is arbitary
plt.figure(figsize = [20,20])
plt.subplot(5,6,7)
plt.plot(R,F,label='Force')
plt.plot(R,V,label='Potential')
plt.plot(R,E,label='Intensity')
plt.legend()
plt.xlabel(r)
plt.ylabel('F,V,E')
plt.subplot(5,5,5)
plt.semilogy(R,F,label='Force')
plt.semilogy(R,V,label='Potential')
plt.semilogy(R,E,label='Intensity')
plt.legend()
plt.xlabel(r)
plt.ylabel('lnF,lnV,lnE')
plt.subplot(5,5,4)
plt.loglog(R,F,label='force')
plt.loglog(R,V,label='potential')
plt.loglog(R,E,label='intensity')
plt.legend()
plt.xlabel('lnr')
plt.ylabel('lnF,lnV,lnE')
data={} #empty dictionary
data.update({"Distance":R,"Force":F,"potential":V,"intensity":E})
import pandas as pd
DF=pd.DataFrame(data)
print(DF)<jupyter_output>Distance         Force     potential     intensity
0            1  1.207437e-43  3.715190e-28  3.715190e-28
1            2  3.018592e-44  1.857595e-28  9.287975e-29
2            3  1.341596e-44  1.238397e-28  4.127989e-29
3            4  7.546480e-45  9.287975e-29  2.321994e-29
4            5  4.829747e-45  7.430380e-29  1.486076e-29
...        ...           ...           ...           ...
3694      3695  8.843731e-51  1.005464e-31  2.721148e-35
3695      3696  8.838946e-51  1.005192e-31  2.719676e-35
3696      3697  8.834165e-51  1.004920e-31  2.718205e-35
3697      3698  8.829387e-51  1.004648e-31  2.716735e-35
3698      3699  8.824614e-51  1.004377e-31  2.715266e-35

[3699 rows x 4 columns]<jupyter_text>Task 2  Electrostatic force vs Gravitational force  For electrostatic force $F=K\\frac{q1q2}{r^2}$  For gravitation force $F = G \\frac{m1m2}{r^2}$<jupyter_code>#for H-atom
def Coulumb(q1,q2,d):
    return(9.1*10e9*q1*q2)/d^2
def Gravvitation(m1,m2,r):
    return(6.67*10e-9*m1*m2)/r^2<jupyter_output><empty_output><jupyter_text>Calculating gravitational and electrostatic force between electron and proton within H-atom and comparing<jupyter_code>def Electrostatic(q1,q2,d):
    return(9.1*10e9* q1* q2)/d**2
Electrostatic(1.6*10e-19,1.6*10e-19,5.29*10e-11) 
#q1=(charge of electron=1.6*10e-19C),q2=(charge of proton=1.6*10e-19),d=(distance between electron and proton=5.29*10e-11)
def Gravitational(m1, m2, r):
    return(6.67*10e-11 *m1 * m2) / r**2
Gravitational(9.11*10e-31,1.67*10e-27,5.29*10e-11)
#m1=(massof electron=9.11*10e-31),m2=(mass of proton=1.67*10e-27),r=(distance between electron and proton=5.79*10e-11)
class Comparision():
    def __init__(self,G,K,m1,m2,q1,q2,r):
        self.G=G
        self.K=K
        self.q1=q1
        self.q2=q2
        self.m1=m1
        self.m2=m2
        self.r=r
    def Gforce(self):
        F1=(self.G*self.m1*self.m2)/(self.r**2)
        return F1
    def Eforce(self):
        F2=(self.K*self.q1*self.q2)/(self.r**2)
        return F2
C=Comparision(6.67e-11,9e9,9.1e-31,1.67e-27,1.6e-19,1.6e-19,5.29e-11)
g=C.Gforce()
e=C.Eforce()
if e>g:
   print("Electrostatic force is greater than Gravitataional force")
if e<g:
   print("Gravitational force is greater than Electrostatic force")
if e==g:
   print("Gravitational force is equal to Electrostatic force")<jupyter_output>Electrostatic force is greater than Gravitataional force<jupyter_text>Using lists to calculate the gravitational and electrostatic force between proton and electron for a range of separation<jupyter_code>#for electrostatic force 
def Force(d):
    q1=1.6*10e-19
    q2=1.6*10e-19
    F=(9*10e7*q1*q2)/d**2
    return F
X=[] #empty list for electrosatic force
R=[] #empty list for distance
for d in range (5,20):
    X.append(d)
    F=Force(d)
    R.append(F)
print(X,R)
#for gravitational force
def Force(d):
    m1=9.1*10e-31
    m2=1.67*10e-27
    F=(6.67*10e-11*m1*m2)/d*2
    return F
X=[]
S=[]
for d in range(5,20):
    X.append(d)
    F=Force(d)
    S.append(F)
print(X,S)
    
class Variation:
    def __init__(self,G,K,m1,m2,q1,q2):
        self.G=G
        self.K=K
        self.m1=m1
        self.m2=m2
        self.q1=q1
        self.q2=q2
    def F1(self,r):
        F1=(self.G*self.m1*self.m2)/(r**2)
        return F1
    def F2(self,r):
        F2=(self.K*self.q1*self.q2)/(r**2)
        return F2

V=Variation(6.67e-11,9e9,9.1e-31,1.67e-27,1.6e-19,1.6e-19)
X=[] #empty list to collect electrostatic force
R=[] #empty list to colect distance
S=[] #empty list to collect gravitational force
for r in range (1,900):
    g=V.F1(r)
    e=V.F2(r)
    X.append(r)
    R.append(g)
    S.append(e)

import matplotlib.pyplot as plt
plt.figure(figsize=[30,30])
plt.subplot(5,5,4)
plt.plot(R,X, label ="Electrostatic force")
plt.plot(X,S, label ="Gravitational force")

import matplotlib.pyplot as plt
plt.figure(figsize=[20,20])
plt.subplot(5,5,5)
plt.semilogy(X,R, label="Electrostatic force")
plt.semilogy(X,S, label="Gravitational force")
plt.legend()
plt.ylabel("Electrostatic and Gravitational force")
plt.xlabel(r)
plt.title("Estat vs Grav force")
plt.subplot(5,5,4)
plt.loglog(X,R,label="Electrostatic force")
plt.loglog(X,S,label="Gravitational force")
plt.legend()
plt.ylabel("Electrosatic and Gravitational force")
plt.xlabel(r)
plt.title("Electrostatic and Gravitational force")<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup