Question: I have written a function on MATLAB for calculating the gamma or LF of an input velocity in m/s. I am having trouble plotting gamma(y)
I have written a function on MATLAB for calculating the gamma or LF of an input velocity in m/s. I am having trouble plotting gamma(y) against velocity(v) and cant find how to run through a function and plot those values. I need to plot the Lorentz factor LF for v between 0 and c (the speed of light). Please explain how and show me using MATLAB.
Here is the function I have:
function [y,v] = Gamma_Function(v)
%Inputs the velocity (v)
%Outputs the Lorentz Factor
c = 299792458; %Speed of light (m/s)
y = ((1)/(sqrt(1-((v^2)/(c^2))))); %Lorentz factor equation
end
Here is what I've tried:
1.
v = 1;
for v = 1:100000:299792458
v = ((v)/(299792458));
[y] = Gamma_Function(v); %calls function
plot(v,y)
xlabel ('Velocity')
ylabel ('Gamma')
grid on
end
2.
[y,v] = Gamma_Function(v);
figure;
plot(y);
hold on;
plot(v);
xlabel ('Velocity')
ylabel ('Gamma')
grid on
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
