Perhaps the most famous equation in physics is E=mc^2 which relates energy E to
ID: 3772819 • Letter: P
Question
Perhaps the most famous equation in physics is E=mc^2 which relates energy E to mass m. The speed of light in a vacuum, c, is the property tht links the two together. The speed of light in a vacuum, is 2.9979x10^8 m/s. Create a function called energy to find the energy corresponding to a given mass in kilograms. Your result will be in joules, since 1 kg m^2/s^2=1 J. Use your function to find the energy corresponding to masses from 1 kg to 10^6 kg. Use the logspace function (consult help logspace) to create an appropriate mass vector. Create a plot of your results. Try using different logarithmic plotting approaches (e.g., semilogy, semilogx, and loglog) to determine the best way to graph your results.Explanation / Answer
% Energy.m
function E=Energy(m,c)
E=m*c.^2;
end
%----------------------------------------------
%demo.m
m=logspace(1,10.^6)
c=2.9979*10.^8;
E=zeros(numel(m),1);
for i=1:numel(m)
E(i)=Energy(m(i),c);
end
figure
loglog(x,y,'-s')
grid on
semilogx(x,y)
semilogy(x,y)