Computer science homework MATLAB
CS122
Homework 1: Algorithms 10 Points Total
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 <fprintf> function to output “speed” in km/h fprintf('The bicycle speed is: %g km/h\n', speed);
%use the <fprintf> function to output “distance” in kilometers – HOMEWORK Q3 Deliverables Type your name and "CS 122-1 HW1" for the 8:00AM MW class, "CS 122-2 HW1” for the 10:20AM MW class, or “CS122-3 for the 12:45PM TuTh class. Also include the due date (September 21, 2016 for the MW sections and September 22 for the TuTh section) as part of the assignment heading.
The deliverable is a hard copy printout of the “bike.m” MATLAB script file (above) with the requested additional syntax included. Copy and paste the “bike.m” script file to a new MATLAB script file, and make the changes that are requested (see “Assignment” and the comments in MATLAB script).
Test your program. Then, copy and paste the resulting “bike.m” syntax into a MS Word document. Include your name, section, and due date – and print the document for submission.
This assignment is due in class on the due date (Wednesday, September 21, 2016 or Thursday September 22, 2016).