필터 지우기
필터 지우기

what is wrong with my code?

조회 수: 1 (최근 30일)
Purvil Patel
Purvil Patel 2017년 4월 30일
댓글: James Tursa 2018년 8월 13일
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.
Problem 6 (light_speed):
Testing with argument(s) 150000000
Feedback: Your program made an error for argument(s) 150000000
Your solution is _not_ correct.
>> [tt ee] = light_speed1([370000000,170000000,530000000])
tt =
20.5473 9.4407 29.4327
ee =229906900 105632900 329326100
  댓글 수: 3
Image Analyst
Image Analyst 2017년 4월 30일
How can that be? There is no way you can get a correct answer if you can't even run the program!
Anupriya Krishnamoorthy
Anupriya Krishnamoorthy 2018년 1월 25일
function [time_in_minutes,distance_in_miles] = light_speed(distance_km) time_in_minutes = distance_km /(18000000); distance_in_miles = distance_km / 1.609; end

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2017년 4월 30일
distances = velocity * time, so time = distances/velocity. Of course you have to make sure the units work out. But you forgot to include your code so we don't know how to fix it. Chances are your unit scaling factors are wrong.

shantam sultania
shantam sultania 2018년 8월 13일
편집: James Tursa 2018년 8월 13일
i have a problem in this code i think that the code is right but the thing is i am always getting only one output
%code is :
function [time,dist] = light_speed(distance)
time = distance /(18000000);
dist = distance / 1.609;
end
%output is
>> light_speed(distance);
>> f=light_speed(distance);
>> f
f =
0.4000 0.6000 0.8000
>>
i am always getting only one output please let me know soon
  댓글 수: 1
James Tursa
James Tursa 2018년 8월 13일
You have to request both outputs on the lhs. E.g.,
[f,d] = light_speed(distance);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by