In MatLab, write an anonymous function to compute the Euclidean distance given two…
- User
In MatLab, write an anonymous function to compute the Euclidean distance given two points (x1, y1) and (x2, y2). Use the following equation to calculate the distance.
Euclidean distance = sqrt((x1-x2)^2 + (y1-y2)^2)
Use this code:
function travelSpeed = CalculateTravelSpeed(startX, startY, endX, endY, travelTime) % startX, startY: Starting coordinates % endX, endY: Ending coordinates % travelTime: Travel time in hours
% Write an anonymous function to compute distance given two coordinates % Function name: EuclideanDist % Function inputs: x1, y1, x2, y2
% EuclideanDist = ...
% Do not modify the statement below travelSpeed = EuclideanDist(startX, startY, endX, endY) / travelTime;
end
- Assistant
function travelSpeed = CalculateTravelSpeed(startX, startY, endX, endY, travelTime) % startX, startY: Starting coordinates % endX, endY: Ending coordinates % travelTime: Travel time in hours
% Write an anonymous function to compute distance given two coordinates % Function name: EuclideanDist % Function inputs: x1, y1, x2, y2 EuclideanDist = @(x1, y1, x2, y2) sqrt((x1-x2)^2 + (y1-y2)^2);
% Do not modify the statement below travelSpeed = EuclideanDist(startX, startY, endX, endY) / travelTime;
end
- User
In MatLab, write a function called CheckInputs which checks if three input parameters are the correct data types. The first, second, and third input variables must be a string, numeric, and logical data type, respectively. The output of CheckInputs should be a logical row array, errorCode, with 4 values. If all the tests pass, then errorCode should consist of only false values. If the 1st input parameter is not a string, the 1st array element in errorCode is set true. If the 2nd input parameter is not a numeric, the 2nd array element in errorCode is set true. If the 3rd input parameter is not a logical variable, the 3rd array element in errorCode is set true. The 4th array element in errorCode is set true if three input parameters are not present.
Use this code:
function errorCode = CheckInputs(name, gpa, enrollStatus) % Your code goes here % end
- Assistant
function errorCode = CheckInputs(name, gpa, enrollStatus) % Initialize errorCode array errorCode = [false false false false];
% Check if all three input parameters are present if nargin < 3 errorCode(4) = true; else % Check if 1st input parameter is a string if ~ischar(name) errorCode(1) = true; end % Check if 2nd input parameter is numeric if ~isnumeric(gpa) errorCode(2) = true; end % Check if 3rd input parameter is logical if ~islogical(enrollStatus) errorCode(3) = true; end endend