Electric-fields.ipynb

In [1]:
from sympy import *
from sympy.vector import CoordSys3D, Vector
import matplotlib.pyplot as plt
import numpy as np
In [2]:
E, epsilon_0, q, q_1, q_2 = symbols('E, epsilon_0, q, q_1, q_2')
r, vec_r, univec_r = symbols('r, {\overrightarrow{{r}}} , {\widehat{{r}}}')
r_A, vec_r_A, univec_r_A = symbols('r_A, {\overrightarrow{{r_A}}} , {\widehat{{r_A}}}')
r_B, vec_r_B, univec_r_B = symbols('r_B, {\overrightarrow{{r_B}}} , {\widehat{{r_B}}}')
In [3]:
Electric_field_Law = Eq(E, 1/(4*pi*epsilon_0) * (q/r**3) * vec_r)
Electric_field_Law
Out[3]:
$\displaystyle E = \frac{q {\overrightarrow{{r}}}}{4 \pi \epsilon_{0} r^{3}}$
In [4]:
value_of_epsilon_0 = Eq(epsilon_0, 8.85148781762039e-12)
value_of_epsilon_0
Out[4]:
$\displaystyle \epsilon_{0} = 8.85148781762039 \cdot 10^{-12}$
In [5]:
N = CoordSys3D('N')

If we have a 2$C$ point charge at point (1, 3) then what will be the field strength at (-2, -4)

In [55]:
A = np.array([3, -5])
B = np.array([-5, 2])
In [56]:
distanceVec = B - A
distanceSca = np.linalg.norm(distanceVec)
In [57]:
plt.figure(figsize = (6, 6))
plt.plot(A[0], A[1], marker = 'o', color = 'blue', markersize = 8, label = 'A - q = 2$C$')
plt.annotate('A', xy = (A[0] + 0.5, A[1]), fontsize = 14)

plt.plot(B[0], B[1], marker = 'o', color = 'red', markersize = 8, label = 'B - Field strength at B')
plt.annotate('B', xy = (B[0] + 0.5, B[1]), fontsize = 14)

plt.arrow(A[0], A[1], distanceVec[0], distanceVec[1], width = 0.15, color = 'lime', label = distanceVec, length_includes_head = True)
plt.annotate(round(distanceSca, 2), xy = (((B[0] + A[0])/2) + 0.5, (B[1] + A[1])/2), fontsize = 14)

#required
plt.legend()
plt.xlim(-6, 6)
plt.ylim(-6, 6)
plt.xticks(np.arange(-6, 7))
plt.yticks(np.arange(-6, 7))
plt.grid()
plt.gca().set_aspect('equal')
In [58]:
vec_r_A = A[0]*N.i + A[1]*N.j
vec_r_A
Out[58]:
$\displaystyle (3)\mathbf{\hat{i}_{N}} + (-5)\mathbf{\hat{j}_{N}}$
In [59]:
vec_r_B = B[0]*N.i + B[1]*N.j
vec_r_B
Out[59]:
$\displaystyle (-5)\mathbf{\hat{i}_{N}} + (2)\mathbf{\hat{j}_{N}}$
In [60]:
vec_r_eq = Eq(vec_r, vec_r_B - vec_r_A, evaluate = False)
vec_r_eq
Out[60]:
$\displaystyle {\overrightarrow{{r}}} = (-8)\mathbf{\hat{i}_{N}} + (7)\mathbf{\hat{j}_{N}}$
In [61]:
r_eq = Eq(r, (vec_r_B - vec_r_A).magnitude())
r_eq
Out[61]:
$\displaystyle r = \sqrt{113}$
In [62]:
q_eq = Eq(q, 2)
q_eq
Out[62]:
$\displaystyle q = 2$
In [65]:
field1 = Electric_field_Law.subs({
    epsilon_0: value_of_epsilon_0.rhs,
    q: q_eq.rhs,
    vec_r: vec_r_eq.rhs,
    r: r_eq.rhs
})
field1.n(4)
Out[65]:
$\displaystyle E = (-1.198 \cdot 10^{8})\mathbf{\hat{i}_{N}} + (1.048 \cdot 10^{8})\mathbf{\hat{j}_{N}}$
In [67]:
plt.figure(figsize = (6, 6))
plt.plot(A[0], A[1], marker = 'o', color = 'blue', markersize = 8, label = 'A - q = 2$C$')
plt.annotate('A', xy = (A[0] + 0.5, A[1]), fontsize = 14)

plt.plot(B[0], B[1], marker = 'o', color = 'red', markersize = 8, label = f'B - ${latex(field1.n(4))}$')
plt.annotate('B', xy = (B[0] + 0.5, B[1]), fontsize = 14)

plt.arrow(A[0], A[1], distanceVec[0], distanceVec[1], width = 0.15, color = 'lime', label = distanceVec, length_includes_head = True)
plt.annotate(round(distanceSca, 2), xy = (((B[0] + A[0])/2) + 0.5, (B[1] + A[1])/2), fontsize = 14)

#required
plt.legend()
plt.xlim(-6, 6)
plt.ylim(-6, 6)
plt.xticks(np.arange(-6, 7))
plt.yticks(np.arange(-6, 7))
plt.grid()
plt.gca().set_aspect('equal')
In [ ]:
 
In [ ]:
 

Machine Learning

  1. Deal Banking Marketing Campaign Dataset With Machine Learning

TensorFlow

  1. Difference Between Scalar, Vector, Matrix and Tensor
  2. TensorFlow Deep Learning Model With IRIS Dataset
  3. Sequence to Sequence Learning With Neural Networks To Perform Number Addition
  4. Image Classification Model MobileNet V2 from TensorFlow Hub
  5. Step by Step Intent Recognition With BERT
  6. Sentiment Analysis for Hotel Reviews With NLTK and Keras
  7. Simple Sequence Prediction With LSTM
  8. Image Classification With ResNet50 Model
  9. Predict Amazon Inc Stock Price with Machine Learning
  10. Predict Diabetes With Machine Learning Algorithms
  11. TensorFlow Build Custom Convolutional Neural Network With MNIST Dataset
  12. Deal Banking Marketing Campaign Dataset With Machine Learning

PySpark

  1. How to Parallelize and Distribute Collection in PySpark
  2. Role of StringIndexer and Pipelines in PySpark ML Feature - Part 1
  3. Role of OneHotEncoder and Pipelines in PySpark ML Feature - Part 2
  4. Feature Transformer VectorAssembler in PySpark ML Feature - Part 3
  5. Logistic Regression in PySpark (ML Feature) with Breast Cancer Data Set

PyTorch

  1. Build the Neural Network with PyTorch
  2. Image Classification with PyTorch
  3. Twitter Sentiment Classification In PyTorch
  4. Training an Image Classifier in Pytorch

Natural Language Processing

  1. Spelling Correction Of The Text Data In Natural Language Processing
  2. Handling Text For Machine Learning
  3. Extracting Text From PDF File in Python Using PyPDF2
  4. How to Collect Data Using Twitter API V2 For Natural Language Processing
  5. Converting Text to Features in Natural Language Processing
  6. Extract A Noun Phrase For A Sentence In Natural Language Processing