whay is it showing error?

[ time1,dist2 ] = light_speed(D)
time1 = ((D)./(18000000));
dist2 = ((D).*(0.6215));
this is code for geting time for light to reach to earth in minute and distance converted to miles. Why is it showing error for argument 150000000 always. though we dont take that distance in vector.

Respuestas (1)

the cyclist
the cyclist el 30 de Abr. de 2017
Editada: the cyclist el 30 de Abr. de 2017

0 votos

I saved this function
function [time1,dist2] = light_speed(D)
time1 = ((D)./(18000000));
dist2 = ((D).*(0.6215));
end
into a file named light_speed.m, and got
[t,d] = light_speed(150000000)
t =
8.3333
d =
9.3225e+07
I don't see a problem.

4 comentarios

Purvil Patel
Purvil Patel el 30 de Abr. de 2017
Yeah exactly but then also autograder showing this error.
Problem 6 (light_speed): Testing with argument(s) 150000000 Feedback: Your function made an error for argument(s) 150000000
Your solution is _not_ correct.
Image Analyst
Image Analyst el 30 de Abr. de 2017
Perhaps you reversed the output arguments compared to what it wants??? Can you post the exact wording of the question?
Roger Stafford
Roger Stafford el 30 de Abr. de 2017
I would suggest that the autograder in your class is set to too great an accuracy. The 150,000,000 kilometers is a bit too large and the ratio .6215 is also a bit high giving a product of 93225000 miles, whereas the official astronomical unit value is 92955807 miles. Try resetting the ratio to .62137119 and the distance to 149597870 kilometers.
the cyclist
the cyclist el 1 de Mayo de 2017
Another possibility is that you have a simple syntax error. Notice that my code is not exactly the same as your code. Compare them line-by-line and perhaps you will expose the error.
For example, are you supposed to submit a function or a script?

Iniciar sesión para comentar.

Preguntada:

el 30 de Abr. de 2017

Comentada:

el 1 de Mayo de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by