Skip to content

Instantly share code, notes, and snippets.

@zrhans
Created April 18, 2018 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zrhans/0c69e06fd4ec44c86743a2d3e5e31d37 to your computer and use it in GitHub Desktop.
Save zrhans/0c69e06fd4ec44c86743a2d3e5e31d37 to your computer and use it in GitHub Desktop.
!gfortran, gcc version 5.4.0 20160609
program forca_magnetica
real :: B = 1.2 ! [mT]
real :: K = 5.3 ! [MeV]
real :: m = 1.6726219 * 1e-27 !1e-27 ! [Kg]
real :: q = 1.60217662 * 1e-19 ! [C]
real :: v = 0.0
! Transforma B [mT] -> [T]
B = B * 1e-3
! Transforma K [MeV] -> [J]
K = K * 1e6 * 1.60 * 1e-19
! Cálculo da Velocidade
v = ( 2.0 * K / m )**0.5
! Cálculo da Força Magnética
F = q * v * B
! Saída de dados - apresentação dos resultados
print *,'**** Sem formatar ****'
print *,"v: ",v
print *,"F: ",F
print*,
print *,'**** Com formatação ****'
print 100,"Velocidade (V) : ",v, "[m/s]"
print 100,"Força magnética (Fb): ",F, "[N]"
100 format(a,es15.2,1x,a)
end program forca_magnetica
@zrhans
Copy link
Author

zrhans commented Apr 18, 2018

Resultado após compilar e executar o código:

cabox@box-codeanywhere:~/workspace$ ./fmagnetica
 ****  Sem formatar  ****
 v:    31843004.0
 F:    6.12217457E-15

 **** Com formatação ****
Velocidade (V)      :        3.18E+07 [m/s]
Força magnética (Fb):        6.12E-15 [N]
cabox@box-codeanywhere:~/workspace$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment