HW 2 - CS 103, Homework Assignment 2 CS 103, Homework...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 103, Homework Assignment 2 CS 103, Homework Assignment 1. Unless otherwise indicated (e.g., “Answer in English”), the answers should be Matlab commands. 1. [Answer in English] Consider this command: fprintf('No.: %g, price= %5.2f.\nTotal is %7.3f\n', 80, 3.1, 4*3.1); a. What happens if \n is replaced by \t ? b. While it is rarely used, fprintf does return a value ( i.e. , in addition to printing something into the command window). The value is the number of characters printed to the screen. Repeat the first fprintf command above in your command window but this time capture the value that is returned as follows: » x = fprintf('No.: %g, price= %5.2f.\nTotal is %7.3f\n', 80, 3.1, 4*3.1); What value does x get? c. Does this value agree with the number of characters visible on the screen? If not, why not? 2. The relation between the velocity and acceleration of an object is given as: v = u + at where u = initial velocity in miles/hour v = final velocity in miles/hour a = acceleration in miles/hour 2 t = time of acceleration in hours Write a sequence of commands to accept the initial and final velocities (both integers) and the time of acceleration (in minutes) from the user (use the input command), and calculate acceleration in miles per hour 2 . (Your answer will probably be a floating point value). Print out your answer using fprintf in the following format (numbers should appear where there are blanks below) with two digits to the right of the decimal place for each: The object has an initial velocity of ______ mph, and undergoes an acceleration of _____ mph2 for _______ minutes, to achieve a final velocity of ___ mph. 3. A course involves 7 graded assignments. The grades in these assignments contribute the following respective percentages of the course grade: 20%, 10%, 30%, 5%, 5%,
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
15%, and 15%. There are 10 students in the course. a. Give one command that sets up a column vector containing these percentages (use 0.20 for 20%, etc.) b. Give a second command that sets up a matrix containing (fictitious) grades for each student for each assignment, letting each grade fall within the range from zero to 100. c. Give a third command that calculates the weighted average for each student and puts them in a column vector. 4.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

HW 2 - CS 103, Homework Assignment 2 CS 103, Homework...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online