clear all format short

Similar documents
PHYS102 EXAM #1 February 17, MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Fall 12 PHY 122 Homework Solutions #2

Physics 2049 Exam 1 Spring 2002

2. Gauss Law [1] Equipment: This is a theoretical lab so your equipment is pencil, paper, and textbook.

Physics Grading Sheet.

SPRING 2014 Department of Physics & Astronomy, UGA PHYS 4202/6202 Electricity and Magnetism II (as of Jan. 07/2014)

The ResistorArray Package

3. A solid conducting sphere has net charge of +6nC. At electrostatic equilibrium the electric field inside the sphere is:

Speed of waves. Apparatus: Long spring, meter stick, spring scale, stopwatch (or cell phone stopwatch)

Package ResistorArray

Scattering amplitudes and the Feynman rules

Phys222 S11 Quiz 2: Chapters Name: = 80 nc, and q = 24 nc in the figure, what is the magnitude of the total electric force on q?

Types of Symmetry. We will be concerned with two types of symmetry.

Drawing Line Graphs. Line graphs indicate continuously changing data. Numbers on line graphs are often approximate figures.

BMT 2014 Symmetry Groups of Regular Polyhedra 22 March 2014

PHYS102 - Gauss s Law.

Physics 222 Quiz 3 Electric Field of Distributed Charge, Form: A

Solution of Matrix Eigenvalue Problem

PHYS 2135 Exam I February 13, 2018

Gauss s Law. Phys102 Lecture 4. Key Points. Electric Flux Gauss s Law Applications of Gauss s Law. References. SFU Ed: 22-1,2,3. 6 th Ed: 16-10,+.

Lecture 3. Electric Field Flux, Gauss Law. Last Lecture: Electric Field Lines

These variables have specific names and I will be using these names. You need to do this as well.

SYMMETRIES IN R 3 NAMITA GUPTA

Homework 7 Solution Chapter 7 - Cosets and Lagrange s theorem. due: Oct. 31.

LECTURE 15 CONDUCTORS, ELECTRIC FLUX & GAUSS S LAW. Instructor: Kazumi Tolich

Planar Graphs (1) Planar Graphs (3) Planar Graphs (2) Planar Graphs (4)

DOING PHYSICS WITH MATLAB ELECTRIC FIELD AND ELECTRIC POTENTIAL: INFINITE CONCENTRIC SQUARE CONDUCTORS

Cecilia first drops off the edge mostly moving parallel the x coordinate. As she gets near bottom of the parabola, she starts moving turning toward

Errors. Intensive Computation. Annalisa Massini 2017/2018

Lecture 4.2 Finite Difference Approximation

Downloaded from

Physics 114 Exam 1 Spring 2013

Cutnell/Johnson Physics

Fluid flow I: The potential function

Physics 114 Exam 1 Fall 2015

Errors Intensive Computation

Gauss Law 1. Name Date Partners GAUSS' LAW. Work together as a group on all questions.

11. Iteration: The while-loop

ENGR Spring Exam 2

STRAIGHT LINE MOTION TEST

Introduction. Pre-Lab Questions: Physics 1CL PERIODIC MOTION - PART II Fall 2009

Essential University Physics

Preliminary Examination, Numerical Analysis, August 2016

AP Physics C - E & M

AP Physics C: Work, Energy, and Power Practice

Ch 24 Electric Flux, & Gauss s Law

AP Physics Study Guide Chapter 17 Electric Potential and Energy Name. Circle the vector quantities below and underline the scalar quantities below

Electric Field. Lab 4: Part 1: Electric Field from One Point Charge. Name: Group Members: Date: TA s Name:

PHYSICS SPRING EXAM 1 - February 12, Name: Recitation Section Number:

ON THE PUZZLES WITH POLYHEDRA AND NUMBERS

PHYS1212 Exam#2 Spring 2014

Differential Operators and the Divergence Theorem

Tycho Brahe and Johannes Kepler

The Story of a Research About the Nets of Platonic Solids with Cabri 3D: Conjectures Related to a Special Net Factor A Window for New Researches

AP Physics Free Response Practice Kinematics

Experiment 6. Coulomb s Law - PRELAB. Lab section: Partner's name(s): Grade: 0. Pre-lab Homework (2 points)

Phys102 General Physics II. Chapter 24: Gauss s Law

How Do You Group It?

Welcome Back to Physics Electric Fields. Micheal Faraday Physics 1308: General Physics II - Professor Jodi Cooley

Summary of free theory: one particle state: vacuum state is annihilated by all a s: then, one particle state has normalization:

Electric flux. Electric Fields and Gauss s Law. Electric flux. Flux through an arbitrary surface

Gauss s Law. 3.1 Quiz. Conference 3. Physics 102 Conference 3. Physics 102 General Physics II. Monday, February 10th, Problem 3.

Explicit Incompressible Euler Solver

Introduction)! Electrostatics is the study of stationary electric charges and fields (as opposed to moving charges and currents)

Chapter 24. Gauss s Law

Theory of Computation Prof. Raghunath Tewari Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Chapter 21 Chapter 23 Gauss Law. Copyright 2014 John Wiley & Sons, Inc. All rights reserved.

Module 2 : Electrostatics Lecture 7 : Electric Flux

2. MATLAB Basics. (d) array1([1 3],end) consists of the elements in the first and third rows on the last column of array1:

Questions Chapter 23 Gauss' Law

Where, ε 0 = Permittivity of free space and = Nm 2 C 2 Therefore, force

Materials: One of each of the following is needed: Cart Meter stick Pulley with clamp 70 cm string Motion Detector

a. Determine the potential energy of the spring as a function of displacement.

Coulomb Law. Purpose In this lab you will use the Coulomb Torsion Balance to show the inverse squared law for electrostatic force between charges.

Physics 121 Common Exam 1, Sample Exam 4 (Fall 2011)

ELECTRIC FORCES AND ELECTRIC FIELDS

PHY102 Electricity Topic 3 (Lectures 4 & 5) Gauss s Law

Name: pd. 7B Work and Energy

Geometry. A. Right Triangle. Legs of a right triangle : a, b. Hypotenuse : c. Altitude : h. Medians : m a, m b, m c. Angles :,

Problem Score 1 /30 2 /15 3 /15 4 /20 5 /20 6 /20 7 /15 8 /25 9 /20 10 /20 Total /200

The Electric Field EM-L2-1

Pd D-D Fusion and Jitterbug Structure

IB Mathematics HL Year 2 Unit 7 (Core Topic 6: Probability and Statistics) Valuable Practice

Convolutional Neural Networks

Review. Spring Semester /21/14. Physics for Scientists & Engineers 2 1

week 3 chapter 28 - Gauss s Law

Notice the minus sign on the adder: it indicates that the lower input is subtracted rather than added.

Solutions to Systems of Linear Equations

Chapter 22 Gauss s law. Electric charge and flux (sec &.3) Gauss s Law (sec &.5) Charges on conductors (sec. 22.6)

Phys 2102 Spring 2002 Exam 1

Phys222 W16 Exam 2: Chapters Key. Name:

Physics 114 Exam 1 Fall 2016

17 M00/430/H(2) B3. This question is about an oscillating magnet.

Point Group Group Theory Assigning the Point Group of a Molecule A. Low Symmetry Groups

Homework 4: Hard-Copy Homework Due Wednesday 2/17

PRACTICE EXAM 1 for Midterm 1

Assignment 1: Due Friday Feb 6 at 6pm

Physics 208, Spring 2015 Exam #1

P202 Practice Exam 1 Spring 2004 Instructor: Prof. Sinova

Lecture 14. PHYC 161 Fall 2016

Transcription:

DESCRIPTION: This code plots electrostatic field lines for a collection of point charges. MAIN GOAL: To draw the field lines in such a way that their volume density is proportional to the electric flux penetrating any finite surface area. MAIN IDEA: Start field lines very close from a given charge. Then, if the initial points are distributed *uniformly* over a tiny sphere surrounding the charge, the propagated lines will automatically "adjust" themselves in space with correct volume density. MAIN PROBLEM: In general, it is impossible to *uniformly* distribute an arbitrary number M of points on the surface of a sphere. That can only be done for M = 4, 6, 8, 12, and 20, which correspond to the number of vertices of the so-called Platonic solids. https://en.wikipedia.org/wiki/platonic_solid NOTE 1: Thus, in our implementation of the code, the number of field lines originating on a given charge is proportional to the charge and equal to the number of vertices of the corresponding Platonic solid. Due to this restriction, only charges q = 1, 1.5, 2, 3, 5, -1, -1.5, -2, -3, -5, may be used. NOTE 2: If net charge is *positive*, only field lines originating on *positive* charges are propagated. In this case, propagation direction is *forward*. If net charge is *negative*, only field lines originating on *negative* charges are propagated. In this case, propagation direction is *backward*. NOTE 3: *Position vectors* should be entered as [1-3 5], or [1, -3, 5], etc. Make sure that the charges are "reasonably well" localized. AUTHOR: Andrei Galiautdinov Department of Physics & Astronomy University of Georgia Athens, GA 30602 ag@physast.uga.edu DATE: 2016 SPRING, February 08. clear all format short %% Welcome: fprintf(1,'* Welcome to PHYS4201/4202 fprintf(1,'* Electrostatic Field Lines Calculator! tocontinue = input('press Enter to Continue: '); %% Some technical details:

fprintf(1,'* Distance of initial line point from corresponding fprintf(1,'* charge, epsilon, epsilon = 0.0001 %%% Choose. Distance of initial point from a charge. fprintf(1,'* Number of iteration steps on each line, N_step, N_step = 80 %%% Choose fprintf(1,'* Size of each iteration step, step_factor, step_factor = 0.002 %%% Choose %% A note on Platonic solids: fprintf(1,'* ATTENTION: fprintf(1,'* fprintf(1,'* The number of field lines originating on a given charge fprintf(1,'* is equal to the number of vertices of the corresponding fprintf(1,'* Platonic solid. fprintf(1,'* fprintf(1,'* https://en.wikipedia.org/wiki/platonic_solid fprintf(1,'* To find the coordinates of initial points of certain fprintf(1,'* field lines requires the knowledge of the Golden ratio: fprintf(1,'* fprintf(1,'* phi = (1+sqrt(5))/2 phi = (1+sqrt(5))/2 tocontinue = input('press Enter to Continue: '); %% Define positive charges: fprintf(1,'* Specify the NUMBER of positive charges: N_q_positive = input('enter N_q_positive NUMBER: ') fprintf(1,'* Available positive charge values: fprintf(1,'* 1, 1.5, 2, 3, 5 % tocontinue = input('press Enter to Continue: '); fprintf(1,'* Begin specifying positive charges and their positions... q_positive = zeros(1,n_q_positive); rq_positive = cell(1,n_q_positive); N_line_positive = zeros(1,n_q_positive) q_positive_net = 0; for n_q_positive = 1:N_q_positive

q_positive n_q_positive q_positive(n_q_positive) = input('enter CHARGE q_positive: ') rq_positive{1,n_q_positive} = input('enter rq_positive POSITION VECTOR: ') if q_positive(n_q_positive) == 1 fprintf(1,'* Charge: q = 1 fprintf(1,'* Number of field lines: 4 (Tetrahedron) N_line_positive(n_q_positive) = floor(4) %%% Notation: r_in_line{n_line,n_q} r_in_line_positive{1,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, 1, 1]/norm([1, 1, 1]); r_in_line_positive{2,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, -1, -1]/norm([1, -1, -1]); r_in_line_positive{3,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, 1, -1]/norm([-1, 1, -1]); r_in_line_positive{4,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, -1, 1]/norm([-1, -1, 1]); elseif q_positive(n_q_positive) == 1.5 fprintf(1,'* Charge: q = 1.5 fprintf(1,'* Number of field lines: 6 (Octahedron) N_line_positive(n_q_positive) = floor(6) r_in_line_positive{1,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, 0, 0]/norm([1, 0, 0]); r_in_line_positive{2,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, 0, 0]/norm([-1, 0, 0]); r_in_line_positive{3,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, 1, 0]/norm([0, 1, 0]); r_in_line_positive{4,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, -1, 0]/norm([0, -1, 0]); r_in_line_positive{5,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, 0, 1]/norm([0, 0, 1]); r_in_line_positive{6,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, 0, -1]/norm([0, 0, -1]); elseif q_positive(n_q_positive) == 2 fprintf(1,'* Charge: q = 2 fprintf(1,'* Number of field lines: 8 (Cube) N_line_positive(n_q_positive) = floor(8) r_in_line_positive{1,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, 1, 1]/norm([1, 1, 1]); r_in_line_positive{2,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, 1, 1]/norm([-1, 1, 1]); r_in_line_positive{3,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, -1, 1]/norm([-1, -1, 1]); r_in_line_positive{4,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, -1, -1]/norm([-1, -1, -1]);

r_in_line_positive{5,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, -1, 1]/norm([1, -1, 1]); r_in_line_positive{6,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, -1, -1]/norm([1, -1, -1]); r_in_line_positive{7,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, 1, -1]/norm([1, 1, -1]); r_in_line_positive{8,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, 1, -1]/norm([-1, 1, -1]); elseif q_positive(n_q_positive) == 3 fprintf(1,'* Charge: q = 3 fprintf(1,'* Number of field lines: 12 (Icosahedron) N_line_positive(n_q_positive) = floor(12) r_in_line_positive{1,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, 1, phi]/norm([0, 1, phi]); r_in_line_positive{2,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, -1, phi]/norm([0, -1, phi]); r_in_line_positive{3,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, 1, -phi]/norm([0, 1, -phi]); r_in_line_positive{4,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, -1,-phi]/norm([0, -1,-phi]); r_in_line_positive{5,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, phi, 0]/norm([1, phi, 0]); r_in_line_positive{6,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, -phi, 0]/norm([1, -phi, 0]); r_in_line_positive{7,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, phi, 0]/norm([-1, phi, 0]); r_in_line_positive{8,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, -phi, 0]/norm([-1, -phi, 0]); r_in_line_positive{9,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[phi, 0, 1]/norm([phi, 0, 1]); r_in_line_positive{10,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-phi, 0, 1]/norm([-phi, 0, 1]); r_in_line_positive{11,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[phi, 0, -1]/norm([phi, 0, -1]); r_in_line_positive{12,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-phi, 0, -1]/norm([-phi, 0, -1]); elseif q_positive(n_q_positive) == 5 fprintf(1,'* Charge: q = 5 fprintf(1,'* Number of field lines: 20 (Dodecahedron) N_line_positive(n_q_positive) = floor(20) r_in_line_positive{1,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, 1, 1]/norm([1, 1, 1]); r_in_line_positive{2,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, 1, 1]/norm([-1, 1, 1]); r_in_line_positive{3,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, -1, 1]/norm([-1, -1, 1]); r_in_line_positive{4,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, -1, -1]/norm([-1, -1, -1]); r_in_line_positive{5,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, -1, 1]/norm([1, -1, 1]); r_in_line_positive{6,n_q_positive} = rq_positive{1,n_q_positive}...

+ epsilon*[1, -1, -1]/norm([1, -1, -1]); r_in_line_positive{7,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1, 1, -1]/norm([1, 1, -1]); r_in_line_positive{8,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1, 1, -1]/norm([-1, 1, -1]); r_in_line_positive{9,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, 1/phi, phi]/norm([0, 1/phi, phi]); r_in_line_positive{10,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, -1/phi, phi]/norm([0, -1/phi, phi]); r_in_line_positive{11,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, 1/phi, -phi]/norm([0, 1/phi, -phi]); r_in_line_positive{12,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[0, -1/phi,-phi]/norm([0, -1/phi,-phi]); r_in_line_positive{13,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1/phi, phi, 0]/norm([1/phi, phi, 0]); r_in_line_positive{14,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[1/phi, -phi, 0]/norm([1/phi, -phi, 0]); r_in_line_positive{15,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1/phi, phi, 0]/norm([-1/phi, phi, 0]); r_in_line_positive{16,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-1/phi, -phi, 0]/norm([-1/phi, -phi, 0]); r_in_line_positive{17,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[phi, 0, 1/phi]/norm([phi, 0, 1/phi]); r_in_line_positive{18,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-phi, 0, 1/phi]/norm([-phi, 0, 1/phi]); r_in_line_positive{19,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[phi, 0, -1/phi]/norm([phi, 0, -1/phi]); r_in_line_positive{20,n_q_positive} = rq_positive{1,n_q_positive}... + epsilon*[-phi, 0, -1/phi]/norm([-phi, 0, -1/phi]); tocontinue = input('press Enter to Continue: '); q_positive_net = q_positive_net + q_positive(n_q_positive) %% Define negative charges: fprintf(1,'* Specify the NUMBER of negative charges: N_q_negative = input('enter N_q_negative NUMBER: ') fprintf(1,'* Available charge values: fprintf(1,'* -1, -1.5, -2, -3, -5 % tocontinue = input('press Enter to Continue: '); fprintf(1,'* Begin specifying negative charges and their positions... q_negative = zeros(1,n_q_negative); rq_negative = cell(1,n_q_negative); N_line_negative = zeros(1,n_q_negative) q_negative_net = 0; for n_q_negative = 1:N_q_negative

q_negative n_q_negative q_negative(n_q_negative) = input('enter CHARGE q_negative: ') rq_negative{1,n_q_negative} = input('enter rq_negative POSITION VECTOR: ') if q_negative(n_q_negative) == -1 fprintf(1,'* Charge: q = -1 fprintf(1,'* Number of field lines: 4 (Tetrahedron) N_line_negative(n_q_negative) = floor(4) r_in_line_negative{1,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, 1, 1]/norm([1, 1, 1]); r_in_line_negative{2,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, -1, -1]/norm([1, -1, -1]); r_in_line_negative{3,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, 1, -1]/norm([-1, 1, -1]); r_in_line_negative{4,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, -1, 1]/norm([-1, -1, 1]); elseif q_negative(n_q_negative) == -1.5 fprintf(1,'* Charge: q = -1.5 fprintf(1,'* Number of field lines: 6 (Octahedron) N_line_negative(n_q_negative) = floor(6) r_in_line_negative{1,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, 0, 0]/norm([1, 0, 0]); r_in_line_negative{2,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, 0, 0]/norm([-1, 0, 0]); r_in_line_negative{3,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, 1, 0]/norm([0, 1, 0]); r_in_line_negative{4,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, -1, 0]/norm([0, -1, 0]); r_in_line_negative{5,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, 0, 1]/norm([0, 0, 1]); r_in_line_negative{6,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, 0, -1]/norm([0, 0, -1]); elseif q_negative(n_q_negative) == -2 fprintf(1,'* Charge: q = -2 fprintf(1,'* Number of field lines: 8 (Cube) N_line_negative(n_q_negative) = floor(8) r_in_line_negative{1,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, 1, 1]/norm([1, 1, 1]); r_in_line_negative{2,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, 1, 1]/norm([-1, 1, 1]); r_in_line_negative{3,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, -1, 1]/norm([-1, -1, 1]); r_in_line_negative{4,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, -1, -1]/norm([-1, -1, -1]);

r_in_line_negative{5,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, -1, 1]/norm([1, -1, 1]); r_in_line_negative{6,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, -1, -1]/norm([1, -1, -1]); r_in_line_negative{7,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, 1, -1]/norm([1, 1, -1]); r_in_line_negative{8,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, 1, -1]/norm([-1, 1, -1]); elseif q_negative(n_q_negative) == -3 fprintf(1,'* Charge: q = -3 fprintf(1,'* Number of field lines: 12 (Icosahedron) N_line_negative(n_q_negative) = floor(12) r_in_line_negative{1,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, 1, phi]/norm([0, 1, phi]); r_in_line_negative{2,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, -1, phi]/norm([0, -1, phi]); r_in_line_negative{3,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, 1, -phi]/norm([0, 1, -phi]); r_in_line_negative{4,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, -1,-phi]/norm([0, -1,-phi]); r_in_line_negative{5,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, phi, 0]/norm([1, phi, 0]); r_in_line_negative{6,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, -phi, 0]/norm([1, -phi, 0]); r_in_line_negative{7,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, phi, 0]/norm([-1, phi, 0]); r_in_line_negative{8,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, -phi, 0]/norm([-1, -phi, 0]); r_in_line_negative{9,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[phi, 0, 1]/norm([phi, 0, 1]); r_in_line_negative{10,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-phi, 0, 1]/norm([-phi, 0, 1]); r_in_line_negative{11,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[phi, 0, -1]/norm([phi, 0, -1]); r_in_line_negative{12,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-phi, 0, -1]/norm([-phi, 0, -1]); elseif q_negative(n_q_negative) == -5 fprintf(1,'* Charge: q = -5 fprintf(1,'* Number of field lines: 20 (Dodecahedron) N_line_negative(n_q_negative) = floor(20) r_in_line_negative{1,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, 1, 1]/norm([1, 1, 1]); r_in_line_negative{2,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, 1, 1]/norm([-1, 1, 1]); r_in_line_negative{3,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, -1, 1]/norm([-1, -1, 1]); r_in_line_negative{4,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, -1, -1]/norm([-1, -1, -1]); r_in_line_negative{5,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, -1, 1]/norm([1, -1, 1]); r_in_line_negative{6,n_q_negative} = rq_negative{1,n_q_negative}...

+ epsilon*[1, -1, -1]/norm([1, -1, -1]); r_in_line_negative{7,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1, 1, -1]/norm([1, 1, -1]); r_in_line_negative{8,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1, 1, -1]/norm([-1, 1, -1]); r_in_line_negative{9,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, 1/phi, phi]/norm([0, 1/phi, phi]); r_in_line_negative{10,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, -1/phi, phi]/norm([0, -1/phi, phi]); r_in_line_negative{11,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, 1/phi, -phi]/norm([0, 1/phi, -phi]); r_in_line_negative{12,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[0, -1/phi,-phi]/norm([0, -1/phi,-phi]); r_in_line_negative{13,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1/phi, phi, 0]/norm([1/phi, phi, 0]); r_in_line_negative{14,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[1/phi, -phi, 0]/norm([1/phi, -phi, 0]); r_in_line_negative{15,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1/phi, phi, 0]/norm([-1/phi, phi, 0]); r_in_line_negative{16,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-1/phi, -phi, 0]/norm([-1/phi, -phi, 0]); r_in_line_negative{17,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[phi, 0, 1/phi]/norm([phi, 0, 1/phi]); r_in_line_negative{18,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-phi, 0, 1/phi]/norm([-phi, 0, 1/phi]); r_in_line_negative{19,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[phi, 0, -1/phi]/norm([phi, 0, -1/phi]); r_in_line_negative{20,n_q_negative} = rq_negative{1,n_q_negative}... + epsilon*[-phi, 0, -1/phi]/norm([-phi, 0, -1/phi]); tocontinue = input('press Enter to Continue: '); q_negative_net = q_negative_net + q_negative(n_q_negative) %% Net charge: q_net = q_positive_net + q_negative_net %% Plotting all charges: fprintf(1,'* Plotting all the charges... fprintf(1,'* Calculating and plotting the field lines... tocontinue = input('press Enter to Continue: '); for n_q_positive = 1:N_q_positive plot3(rq_positive{1,n_q_positive}(1),... rq_positive{1,n_q_positive}(2),... rq_positive{1,n_q_positive}(3),... 'r*',... 'linewidth',1.0) hold on

for n_q_negative = 1:N_q_negative plot3(rq_negative{1,n_q_negative}(1),... rq_negative{1,n_q_negative}(2),... rq_negative{1,n_q_negative}(3),... 'b*',... 'linewidth',1.0) hold on %% Check which lines to plot: positive or negative: if q_net >= 0 %% Build all lines for each of the positive charges: for n_q_positive = 1:N_q_positive for n_line_positive = 1:N_line_positive(n_q_positive) r_in = r_in_line_positive{n_line_positive,n_q_positive}; Calculating a given field line: N_step; %%% Chosen above x = zeros(1,n_step); y = zeros(1,n_step); z = zeros(1,n_step); Ex = zeros(1,n_step); Ey = zeros(1,n_step); Ez = zeros(1,n_step); Ex_quivered = zeros(1,n_step); Ey_quivered = zeros(1,n_step); Ez_quivered = zeros(1,n_step); dr = [0, 0, 0]; %%% vector r = r_in; for n_step = 1:N_step n_step; New position: x(n_step) = r(1) + (n_step-1)*dr(1); y(n_step) = r(2) + (n_step-1)*dr(2); z(n_step) = r(3) + (n_step-1)*dr(3); r = [x(n_step), y(n_step), z(n_step)]; %%% vector E_net = [0, 0, 0]; for m_q_positive = 1:N_q_positive r_from_q = r - rq_positive{1,m_q_positive}; %%% vector r_from_q_norm = norm(r_from_q); r_from_q_hat = r_from_q/r_from_q_norm; %%% vector E_from_q =... q_positive(m_q_positive)*r_from_q_hat/r_from_q_norm^2; Net E-field: E_net = E_net + E_from_q;

if N_q_negative > 0 for m_q_negative = 1:N_q_negative r_from_q = r - rq_negative{1,m_q_negative}; %%% vector r_from_q_norm = norm(r_from_q); r_from_q_hat = r_from_q/r_from_q_norm; %%% vector E_from_q =... q_negative(m_q_negative)*r_from_q_hat/r_from_q_norm^2; Net E-field: E_net = E_net + E_from_q; Ex(n_step) = E_net(1); Ey(n_step) = E_net(2); Ez(n_step) = E_net(3); E_net_norm = norm(e_net); E_net_normalized = E_net/E_net_norm; Ex_quivered(n_step) = E_net_normalized(1); Ey_quivered(n_step) = E_net_normalized(2); Ez_quivered(n_step) = E_net_normalized(3); Displacement along the E-line: step_factor; %%% Chosen above Sign of q determines E-line propagation direction: step_r_factor =... step_factor*q_positive(n_q_positive)/abs(q_positive(n_q_positive)); dr = step_r_factor*e_net_normalized; %%% vector quiver3(x,y,z,ex_quivered,ey_quivered,ez_quivered,0.25,'r-',... 'linewidth',1.0) hold on elseif q_net < 0 %% Build all lines for each of the negative charges: for n_q_negative = 1:N_q_negative for n_line_negative = 1:N_line_negative(n_q_negative) r_in = r_in_line_negative{n_line_negative,n_q_negative}; Calculating a given field line: N_step; %%% Chosen above x = zeros(1,n_step); y = zeros(1,n_step); z = zeros(1,n_step); Ex = zeros(1,n_step); Ey = zeros(1,n_step);

Ez = zeros(1,n_step); Ex_quivered = zeros(1,n_step); Ey_quivered = zeros(1,n_step); Ez_quivered = zeros(1,n_step); dr = [0, 0, 0]; %%% vector r = r_in; for n_step = 1:N_step n_step; New position: x(n_step) = r(1) + (n_step-1)*dr(1); y(n_step) = r(2) + (n_step-1)*dr(2); z(n_step) = r(3) + (n_step-1)*dr(3); r = [x(n_step), y(n_step), z(n_step)]; %%% vector E_net = [0, 0, 0]; for m_q_negative = 1:N_q_negative r_from_q = r - rq_negative{1,m_q_negative}; %%% vector r_from_q_norm = norm(r_from_q); r_from_q_hat = r_from_q/r_from_q_norm; %%% vector E_from_q =... q_negative(m_q_negative)*r_from_q_hat/r_from_q_norm^2; Net E-field: E_net = E_net + E_from_q; if N_q_positive > 0 for m_q_positive = 1:N_q_positive r_from_q = r - rq_positive{1,m_q_positive}; %%% vector r_from_q_norm = norm(r_from_q); r_from_q_hat = r_from_q/r_from_q_norm; %%% vector E_from_q =... q_positive(m_q_positive)*r_from_q_hat/r_from_q_norm^2; Net E-field: E_net = E_net + E_from_q; Ex(n_step) = E_net(1); Ey(n_step) = E_net(2); Ez(n_step) = E_net(3); E_net_norm = norm(e_net); E_net_normalized = E_net/E_net_norm; Ex_quivered(n_step) = E_net_normalized(1); Ey_quivered(n_step) = E_net_normalized(2); Ez_quivered(n_step) = E_net_normalized(3); Displacement along the E-line: step_factor; %%% Chosen above Sign of q determines E-line propagation direction: step_r_factor =... step_factor*q_negative(n_q_negative)/abs(q_negative(n_q_negative)); dr = step_r_factor*e_net_normalized; %%% vector

quiver3(x,y,z,ex_quivered,ey_quivered,ez_quivered,0.25,'b-',... 'linewidth',1.0) hold on grid on axis tight set(gca,'box','on'); %%% BOX set(gca,'fontsize',12) %%% the fontsize of the axes tick labels xlabel('x'), ylabel('y'), zlabel('z') title({... ['q_{net} = ',num2str(q_net),... ' N_{+} = ',num2str(n_q_positive),... ' q_{+} = \{',num2str(q_positive),'\}'... ' N_{-} = ',num2str(n_q_negative),... ' q_{-} = \{',num2str(q_negative),'\}'... ],... ['\epsilon = ', num2str(epsilon),... ' N_{step} = ',num2str(n_step),... ' step_{factor} = ',num2str(step_factor),... ],... }) hold off fprintf(1,'* Displaying all charges and their positions: q_net q_positive, celldisp(rq_positive) q_negative, celldisp(rq_negative) fprintf(1,'* Calculation and plotting the field lines is complete. fprintf(1,'* fprintf(1,'* END OF CODE.