Write additional syntax to create an input variable named


Algorithms Assignment

The following 3 tasks are to be completed for Homework 1 - using the following MATLAB syntax for the script file "bike.m"

1) Write additional syntax to create an INPUT variable named time and prompt the user for the amount of time pedaling the bicycle (in hours).

2) Then, create a distance calculation assigned to the variable distance that is equal to the variable time multiplied by the variable speed.

3) OUTPUT the calculated distance value using the fprintf function. What are the distance units? Include the units in the fprintf statement.

%bike.m - calculates speed of a bicycle in km/h
%define known input variable values
wheel = 622;
tire = 28;
fgear = 40;
rgear = 22;
%prompt user for cadence (can be a vector of multiple cadence values)
cadence = input('rpm: ');
%prompt user for time (amount of time pedaling) - HOMEWORK Q1
%caculate meters of development (modev) and speed
modev = (wheel + 2 * tire) * (fgear/rgear) * pi * 0.001;
speed = modev * cadence * 0.06;
%calculate distance traveled = time * speed - HOMEWORK Q2
%use the function to output "speed" in km/h
fprintf('The bicycle speed is: %g km/h\n', speed);
%use the function to output "distance" in kilometers - HOMEWORK Q3

Solution Preview :

Prepared by a verified Expert
MATLAB Programming: Write additional syntax to create an input variable named
Reference No:- TGS01597892

Now Priced at $30 (50% Discount)

Recommended (90%)

Rated (4.3/5)