Advertisement
hiddenGem

Pendulum in an Electric Field

May 28th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.49 KB | None | 0 0
  1. %% Pendulum in an Electric Field
  2. % Can calculate the angle of deflection in degrees and radians of a
  3. % pendulum in an electric field. Notes are at the bottom of the page
  4.  
  5. % Constants
  6. g = 9.81;            %[m/s^2] Acceleration due to gravity on earth
  7.  
  8. % Variables
  9. q = input('The charge of mass object in Coulombs\n');
  10. E = input('The electric field in N/C\n');
  11. m = input('The mass of the charged object in kg\n');
  12. % Optional variable for relative permittivity
  13. Er = input('The relative permittivity if applicable (if not enter 1)\n');
  14.  
  15. % Equations and output
  16. radians = round(atan((q*E/Er)/(m*g)), 3, 'significant');
  17. degrees = round(atand((q*E/Er)/(m*g)), 3, 'significant');
  18. a = input('Do you want the angle in radians, degrees, or both?\n');
  19. switch a
  20.     case 1
  21.         fprintf('The angle in radians is %i', radians)
  22.     case 2
  23.         fprintf('The angle in degrees is %i', degrees)
  24.     case 3
  25.         fprintf('The angle in radians and degrees is %i and %i', radians, degrees)
  26. end
  27.  
  28.  
  29. %{
  30. For the value of the electric field,
  31.     V/m is equal to N/C so no conversions are necessary if the electric field
  32.     is given in those units
  33. This program rounds to 3 significant figures.
  34.     To change or remove this option see line 16 and 17
  35.  
  36. This paste is different than my past "Function: Pendulum in Electric"
  37.     Obviously that one is a function file and it will not ask for inputs.
  38.     The other file does NOT round to three significant figures.
  39.     Answers in the other paste will be given in matrix form.
  40. %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement