Advertisement
hiddenGem

Insulating Sphere

May 28th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.94 KB | None | 0 0
  1. %% Insulating sphere
  2. % Calculates the electric flux from distance r for an INSULATING sphere
  3. % Notes and clarifications for the code are at the bottom
  4.  
  5. % Constants
  6. k = 8.99*10^9;               %[N*m^2/C^2] Coulombs constant
  7.  
  8. % Variables and inputs
  9. R = input('What is the radius of the sphere in meters?\n');
  10. r = input('What is distance, in meters, away from center of the sphere?\n');
  11. Q = input('What is the net charge on the conducting sphere in Coulombs?\n');
  12.  
  13. % Equation and outputs
  14. if r < R
  15.     Ein = (k*Q*r)/R^3;
  16.     fprintf('The distance is inside the sphere.\n The electric flux is %i N/C \n',Ein)
  17. elseif r == R || r > R
  18.     Eout = k*(Q/r^2);
  19.     fprintf('The distance is outside the radius. The electric flux is %i N/C \n', Eout)
  20. end
  21.  
  22. %{
  23. Under the assumption there is an electric charge evenly distributed
  24. throughout the insulating material.
  25.  
  26. See paste "Conducting Sphere" for a net charge that sits on the surface of
  27. the sphere
  28. %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement