Use this document template to report your answers. Enter all lab partner names at the top of first page.

computer science

Description

 

Instructions:

1. Use this document template to report your answers. Enter all lab partner names at the top of first page.

2. You don’t need to finish your lab work during the corresponding lab session.

3. Name the complete document as follows:

 

LastName_FirstName_CS104_Lab9_Report.doc

 

4. Submit the final document to Blackboard Assignments section before the due date. No late submissions will be accepted.

5. ALL lab partners need to submit a report, even if it is the same document.

6. You can use Matlab diary function to save all your Matlab Command Window interactions to a text file (start with diary, stop with diary off - a new text file called diary will appear in Current Folder section of Matlab interface).

 

Objectives:

1. (20 points) Demonstrate the ability to solve problems using Matlab loops.

 

Problem 1 [5 pts]:

Here’s a game, let’s call it TriStick, pick three sticks each having a random length between zero and one. You win if you can form a triangle whose sides are the sticks. Otherwise you lose (see image below for illustration).

 

Lab09Image01

 

Write a Matlab SCRIPT that estimates the probability of winning a game of TriStick by simulating a million games and counting the number of wins. Output a text message that includes the probability estimate as a percentage on screen. Write your code below:

 

Your SCRIPT code (copy/paste or type in) [4.5 out of 5 pts]:

 

 

 

 

 

 

 

 

 

 

Now, run your script and show the Command Window command(s) and output in the box below:

 

Command Window output [0.5 out of 5 pts]:


Related Questions in computer science category