# Write a function that receives an input argument of a number of kilometers (km) and will output the conversions into both miles (mi) and US nautical miles (n.m.). Use the conversions: 1 km = 0.621 mi and 1 km = 0.540 n.m.

39 views (last 30 days)
Malik McMillon on 19 Oct 2016
Commented: Walter Roberson on 1 Oct 2019
Write a function that receives an input argument of a number of kilometers (km) and will output the conversions into both miles (mi) and US nautical miles (n.m.). Use the conversions: 1 km = 0.621 mi and 1 km = 0.540 n.m.
Steven Lord on 19 Oct 2016
Show what you've done to try to solve this problem and ask a specific question about where you're stuck and you may receive some guidance.

Soma Ardhanareeswaran on 21 Oct 2016

James Tursa on 21 Oct 2016
Edited: James Tursa on 21 Oct 2016
1) Create a function file called myconversion.m in your working directory. E.g.,
edit myconversion.m
2) Put the following code into this file:
function [x_mi,x_nm] = myconversion(x_km)
% Insert your code here to convert x_km to x_mi
% Insert your code here to convert x_km to x_nm
return
end
Insert your code for the conversions into the places indicated. Also add comments to this file to state the purpose of the function, show the calling syntax, and explain what the inputs and outputs are.

Christian Hernandez on 1 Oct 2019
function [x_mi,x_nm] = myconversion(x_km)
% Insert your code here to convert x_km to x_mi
% Insert your code here to convert x_km to x_nm
return
end
Walter Roberson on 1 Oct 2019
It is not clear how this differs from James Tursa's guideance ?