Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a code to find the electric field and the potential. i want to re write it as class but in easier way The

I have a code to find the electric field and the potential. i want to re write it as class but in easier way

The code:

class ChargedParticle: def __init__(self, pos, charge): self.pos = np.asarray(pos) self.charge = charge def compute_field(self, x, y): # this part i want to rewrite it X, Y = np.meshgrid(x, y) u_i = np.hstack((X.ravel()[:, np.newaxis], Y.ravel()[:, np.newaxis])) - self.pos r = np.sqrt((X - self.pos[0]) ** 2 + (Y - self.pos[1]) ** 2) field = ((self.charge / r ** 2).ravel()[:, np.newaxis] * u_i).reshape(X.shape + (2,)) return field def compute_potential(self, x, y): X, Y = np.meshgrid(x, y) r = np.sqrt((X - self.pos[0]) ** 2 + (Y - self.pos[1]) ** 2) potential = self.charge / r return potential

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Physics For Scientists And Engineers With Modern Physics

Authors: Raymond A. Serway, John W. Jewett

9th Edition

1133954057, 978-1133954057

More Books

Students also viewed these Physics questions

Question

What was not clear to investors in subprime mortgages?? p-9687

Answered: 1 week ago

Question

5. How can I help others in the network achieve their goals?

Answered: 1 week ago