Effacer les filtres
Effacer les filtres

A function related with speed light and time

14 vues (au cours des 30 derniers jours)
Lewis HC
Lewis HC le 15 Déc 2022
Modifié(e) : Lewis HC le 22 Déc 2022
Hello dear friends, I need to write a function called Ltime that takes as input a row vector of distances in miles and returns two output arguments. The first output argument is a row vector of the corresponding time in minutes for light to travel each distance, it takes light a little over 8 minutes to travel from the sun to the earth which are 92.9 million miles apart. The second output argument is a vector of the inputs in kilometers. The speed of light is 300,000 km/s and a mile is 1,609 km.
Also I should this code for getting the function: [a,b]=Ltime([10,100,1000,10000]). Thank you!
  1 commentaire
Walter Roberson
Walter Roberson le 16 Déc 2022
Your code does not define A, B, C or D before the second line is executed . Are they functions that take no arguments? And then you overwrite the input M , and then you overwrite the four functions??
I am having trouble figuring out what anything in your function has to do with the assignment, with the exception that V=300000 looks like an approximation for the speed of light (which would normally be coded as c instead of V)

Connectez-vous pour commenter.

Réponse acceptée

William Rose
William Rose le 16 Déc 2022
It is nice to see that you have made an attempt before posting your question.
@Walter Roberson is exactly right as usual.
You had the right idea when you wrote "[a,b]=Ltime([10,100,1000,10000])". Use a syntax like that in the funciton declaration (line 1).
Short version
function [a,b]=Ltime(M)
Longer version
function [a,b]=Ltime(M)
%LTIME returns light time in minutes, and distance in km.
% M=vector of distances in miles
% a=time in minutes for light to travel the distances in M
% b=distances M, converted to km
c=2.9979e5; %speed of light in km/s
b=M*1.6093; %convert miles to km
a=b/(c*60); %time in minutes
Note that 1.6093/(c*60)=8.948e-8, the constant in the short version of the function.
  4 commentaires
William Rose
William Rose le 16 Déc 2022
@Lewis HC, you're welcome.
"there are small problems that confuse me sometimes"
I often feel the same way, and I bet most Matlab users do.
William Rose
William Rose le 16 Déc 2022
@Walter Roberson, thank you for the feedback. Good point. I guess I was more helpful than I should have been because he showed his own code and his other idea. Which many people don't do.

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by