CS107 – Computing for Math & Science Spring 2020 • Assignment 1
Due Date:
Before 11:59 p.m. on Friday, February 7, 2020
Accept Until:
Before 11:59 p.m. on Friday, February 14, 2020
Evaluation:
20 points
Submit to Canvas:
assignment1_answers.docx file
To get credit for this assignment:
1. Your file must be uploaded to Canvas on time.
2. The TA should be able to display your file by just clicking on its link.
Background: This assignment is designed to practice the introductory MATLAB concepts, commands and functions. For this assignment, you will upload your answers file to Canvas so that it can be accessed by just clicking on the file’s link.
Directions:
Create a new Word file (you may use MS Word or ScarletDocs) and save it as assignment1_answers.docx
Answer the questions listed on the next page and place the answers on the document you just created.
Enter your name and section at the top of the page.
After answering the questions, download and save your file to a folder of your choosing.
Upload and submit your assignment1_answers.docx file to Canvas using the Canvas->
Assignments link.
Page 1 of 4
Introduction to MATLAB related questions. Show your work by copying it from the MATLAB Command Window and pasting onto your Word solution file.
1) (2 points) Load the the following into the variable myVar sequentially. What would be the final value of myVar?
3+8 7-1 myVar + 9 myVar * 2 myVar – 5
2) (2 points) Generate a random real number in the range (0, 2)
3) (2 points) Generate a random real number in the range (18, 27)
4) (2 points) Generate a random integer number in the range 1 to 10.
5) (2 points) Use the help command for the function floor. After reading about its usage, use it twice with the following data:
1.37 2.92
6) (2 points) Use the help command for the function round. After reading about its usage, use it twice with the following data:
3.817, 1 5.768, 2
Page 2 of 4
7) (2 points) Create an assignment statement to load the result of the multiplication 7 * 3 into the variable myResult. Then, use the command whos to see the size and class of myResult. Use the function int32 with myResult as data and store the result in the variable myResult2. Use the whos function to show the sizes and types (classes) of myResult and myResult2.
8) (2 points) Calculate the volume of a cone with a 5” radius and 7” height using the formula: (1/3).π.r2.h (note: the periods indicate multiplications)
Assign the result of the formula to the variable volume. First load the data required into appropriately named variables and then execute the formula by using an assignment.
9) (2 points) Calculate the longer side of a right triangle with sides 7” and 9” by using the formula:
√(a2 + b2)
Assign the result of the formula to the variable longerSide. First load the data required into appropriately named variables and then execute the formula by using an assignment.
10) (2 points) Perform the following commands: load 7 into the variable x, then load the logical comparison x > 2 into the variable y. Run the function whos to display the size and class of the variables x and y. Do they belong to equal classes (datatypes) ?
Now perform the following commands: load ‘7’ (that’s the character 7) into x. Run whos again to look at the current size and class of x.
Then execute an assignment to load the calculation x + y into the variable finalResult. What’s the class of finalResult? What’s the reason for the value of finalResult?
Submit the assignment by uploading your file to Canvas Notes:
– Log on to your Canvas account and upload your completed file.
– After uploading your file, check your upload by clicking on the file’s link.
Page 3 of 4
– Your TA should be able to check your work by clicking on the file’s link. References:
Course website on Canvas
MATLAB textbook, chapter 1
Lectures, recitations
Page 4 of 4