Question

Write a function called light_speed that takes as input a row vector of distances in kilometers...

Write a function called light_speed that takes as input a row vector of distances in kilometers 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 150 million kilometers away. The second output contains the input distances converted to miles. Assume that the speed of light is 300,000 km/s and that one mile equals 1.609 km.

(You can not use if, if else, or any types of loops to solve)

Homework Answers

Answer #1
%%save as light_time.m in matlab File->New
%300000km/s to km/min
%1min=60s
%1s=(1/60)min
%300000*60=1.8e7
%t=speed*dis
%distance=speed*time
%convert kms to miles
%1mile=1.609

%function defintion

function [time,distance]=light_time(dis)
    time=(1./1.8e7).*dis;
    distance=1.609.*dis;
end

------------------------------------------------------------------------------------------------------

Sample output:

dis is vector that contains distances

from earth to moon=384000

sun to earth=1.496e8

sun to mars=2.2794e8

-----------------------------------------------------------

From the matlab command line,

Create a distance vector with name distance

--> distance = [384000 1.496e8 2.2794e8];
--> [time,distance]=light_time(distance)
time =
    0.0213    8.3111   12.6633
distance =
    617856 240706400 366755460

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT