Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

these problems are in Matlab Problem 4 Imagine a gashapon toy capsule vending machine that randomly dispenses two types of toys: one that is common

image text in transcribed

image text in transcribed

image text in transcribed

these problems are in Matlab

Problem 4 Imagine a gashapon toy capsule vending machine that randomly dispenses two types of toys: one that is common and one that is rare. Suppose that the probability of getting a special rare toy capsule from the machine is only 5% and that the machine has an infinite supply of toys. The probability of first getting a rare toy after a total of k successive attempts is as follows: P(k)= (1-pip where p is the probability of a successful trial (p = 5% = 0.05), k is the number of trials (k = 0, 1, 2, ...), and P(k) is the probability of the kih trial being the first successful trial (Os P(k) s 1). a) Write a program that computes the probability P(k) that you will get your first special toy capsule on the kin attempt, with k being input by the user (simply plug in the equation shown above). Display your results with 6 decimal points using fprintf(). Put P(k) in a 1x1 vector called "P". b) Now write a program that prompts the user for a total number of attempts N (ONLY accept integer values such that N 1; reject invalid input until the user provides a suitable value). After you have N, use it to set up a for loop that will sum all P(k) for k N. The significance of this is that your program will now be computing Plk sN), which is the probability of successfully getting the rare toy capsule in N or less trials. For example, if you were to input N = 3, your code should make the following calculation using a for loop: Plk S 3) = P(k = 1) + P(k = 2) + P(k = 3) %Adding probability you "win" on the 14, 2nd, or 3rd trial Plk 5 3) = ((1 -0.001) - 0.001) + (1 -0.001)21 0.001) + ((1 -0.001)310.001) Plk 3) = 0.00299700 = 0.2997% Problem 2 Write a program that implements a simple number guessing game. The script should first generate a random number with two significant decimal places that is in the range of -10 to 10 (use the functions rand() and round() to do this). Next, the player must be given the chance to guess at the correct number, with their guess being rounded to two decimal places. If the user guesses a number greater than 10, their guess should be set to 10, whereas if they quess a number less than -10, their guess should be set to - 10. After the player has made their guess, the program should indicate how close the guess is to being correct. The responses that the program should give are as follows: "You won" if the exact correct number is guessed "You were incredibly close" if the guess is within 0.05 of the correct number "You were very close" if the guess is between 0.05 and 0.1 away from the correct number "You were close" if the guess is between 0.1 and 0.5 away from the correct number "You were kind of close" if the guess is between 0.5 and 1 away from the correct number "You were at least in the ballpark if the guess is between 1 and 2 away from the correct number "You were not close" if the guess is between 2 and 5 away from the correct number "You were way off" if the guess is further than 5 away from the correct number The program must allow the user to keep guessing until they eventually guess the correct number. This can be accomplished through the use of a while() loop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions