Search Program on this blog

Tuesday 18 August 2015

Write a function called light_time that takes as input a row vector of distances in miles and returns two row vectors of the same length. Each element of the first output argument is the time in minutes that light would take to travel the distance specified by the corresponding element of the input vector. To check your math, it takes a little more than 8 minutes for sunlight to reach Earth which is 92.9 million miles away. The second output contains the input distances converted to kilometers. Assume that the speed of light is 300,000 km/s and that one mile equals 1.609 km.

function [x,y] = light_time(a)
%Input a is row vector of distances in miles
%Output x is row vector of time in minutes that light would take to travel the distance
%       y is row vector of distance in kilometres
%Example:
%    a = [92.9 141.6 483.8]
%    [x,y]=light_time(a)
x = (1.609/18e6) .* a; %time in minutes, 8 minutes for 92.9 million miles
y = 1.609 .* a; %distance in kilometres, 1 mile = 1.609km

2 comments:

  1. I would recommend my profile is important to me, I invite you to discuss this topic...
    melancong

    ReplyDelete
  2. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. Visit site webstagram to find instagram for yourself.

    ReplyDelete