Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CODE IN MATLAB Submission: Publish your script file to PDF and upload that PDF to Canvas Question1 Board 10 -4 10 10 -5 10 Figure
CODE IN MATLAB
Submission: Publish your script file to PDF and upload that PDF to Canvas Question1 Board 10 -4 10 10 -5 10 Figure 1 - 20x20 board with three concentric circles There is a 20x20 square board and there are concentric circles in the board with radii 3, 5, and 10. A dart player throws 10 darts on the board randomly, such that any place on the board can be hit with an equal chance. In this question, you will estimate how many of darts hit areas indicated by A, B, Cand D in Figure1 Part a Generate two 1D arrays of random numbers with uniform distribution using random function. The arrays should contain 10 elements, which are between -10 and 10. Name your arrays as Dx and Dy. The elements in Dx and Dy are the x and y coordinates of the point where the dart hits the board Next copy and paste the following piece of code on the next line. This code makes a figure of the board and marks the locations where the dart hits with an. R1=10; % radius of the outer circle R2-5; % radius of the middle circle R3-3; % radius of the inner circle the ta-linspace (0,2*pi, 100); % angle array figure % new figure hold on % hold the current figure XX1-[-10,-10, 10, 10]; % square board X coordinates YY1-[-10, 10, 10,-10]; % square board Y coordinates fill (XX1,YY1, 'g'); % plot the square board fill (R1 * cos (theta), R1 * sin (theta), 'c'); % plot outer circle fill (R2*cos (theta), R2 * sin (theta), 'r'); % plot middle circle fill (R3 * cos (theta) , R3*sin (theta), 'y'); % plot outer circle 1 of 4 plot (Dx, Dy, 'x'); % Mark dart positions on the board with an 'x'. hold off % release the figure axis equal % make aspect ratio of x and y axes equal x1in([-10, 10]) % set x-axis limits ylim ([-10, 10]) % set y-axis limits Part b Find the number of darts that hit inside the areas indicated by A, B, C and D in the figure. Use logical indexing to find the results for each area. Display your answers using fprintf( or display) (Hint: The point (Dx,Dy) is inside the circle is the condition Da +Dy SR is satisfied) Part c Calculate the Score using if-else statements: i.) Give score as 10 if the dart hits in area Cequal to 2 times. ii.) Give score as 20 if the dart hits in area C greater than 2 but less than 5 times. iii.) Give score as 50 if the dart hits in area C greater than or equal to 5 times but less than 9 times. iv.) Give score as 100 if the dart hits in area C greater than or equal to 9 times. v.) Give score as 0 if the dart hits in area C0 or 1 times. Display the Score. Part d Display the following message to the player based on the scores using switch-case statements: a. score is 100, display "Congratulations, you get $100" b. score is 50, display "Congratulations, you get $50" c. score is 20, display "Congratulations, you get $10" d. score is 10, display "You did not win any money, but you get free ice cream!" d. score is 0, display "You did not win any money. Wish you better luck next timeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started