BME4503C MatLab On-Ramp Assignment 1

docx

School

University of Florida *

*We aren’t endorsed by this school

Course

4503

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

3

Uploaded by erikanoel34

Report
HOMEWORK Do exercise 1, 2, 3, 4 (slide 27, 29, 31, 34) and submit as scripts that can be run. 100% will be given only to scripts without errors. SLIDE 25 Exercise 1: New Script File § Right click in the current folder window in MATLAB and create a new folder named whatever you would like. § Double click on the folder to make it your current folder. § Clear your MATLAB workspace by typing clear at the command prompt. § Click on New Script to open a blank script file. § Type the commands on the next slide into the editor window then save the file as CircleScript in your newly created folder. SLIDE 26
SLIDE 27 Exercise 1: Run the Script File § Now run your script file by clicking on the Green Arrow in the m-file editor window. § Notice that every single variable defined in the script file (radius, area, and circum) appears in the Workspace Window. Area and circum are also displayed in the Command Window because of the disp command. § Clear the workspace window by typing clear at the command prompt. § At the command prompt, type the name of your script file: >> CircleScript . Note, that the results are exactly the same as before. SLIDE 29 Exercise 2: Another Script File § Create a new script file called SphereScript that will compute and display the surface area and the volume of a sphere. SLIDE 31 Problem 3 Plot tan(x) from 3π/2 to 3π/2. Since tan(x) is undefined (approaches ∞) at odd multiples of π/2, your graph will look seriously distorted because the values are so huge as the angle approaches the asymptotes that the smaller values get swamped out. >> axis([-3*pi/2 3*pi/2 -10 10]) to make a better plot of tan(x) from 3π/2 to 3π/2 . The axis commands specifies a range for the x-axis (3π/2 to 3π/2) and a range for the y-axis (-10 to 10). Using the axis command after the plot statement will re-set the axis. SLIDE 34 Loop Homework - Problem 4 Write a MATLAB script that will allow a user to play the dice game: Under and Over Seven. The rules are pretty simple: 1. The game is played with two dice 2. The player specifies how much money he/she is betting on the roll 3. The player bets whether he/she will roll Under 7, Over 7, or Exactly 7 4. The player specifies how much money he/she is betting on the roll 5. The player rolls the dice 6. If the player bets incorrectly, he/she loses the amount of money in the bet 7. If the player bets correctly, the payoff is 1:1 for Under 7 and for Over 7 (that is, if the bet was $1 then the player wins $1) and is 4:1 for Exactly 7 (that is, if the bet was $1 then the
player wins $4 for betting on and successfully rolling a 7). § Your program should begin by asking the player the total amount of money that he/she has to play this game. Throughout the game, your function will keep track of how much money the player has left based on wins and losses. § The player should then be asked to place his/her bet (Over 7, Under 7, Exactly 7) and the amount of money for the bet. If the player tries to bet more than he/she has, prompt for a new bet amount. § Roll the two dice and display the results (the number on each dice and win or lose). Use the randi function to do this.§ Calculate and display to the user his/her new balance (total amount of money he/she has now). § If the balance is greater than zero, ask the user if he/she would like to play again. If the user says answers yes, prompt for a bet and a betting amount and run through the cycle again. § The game (program) should end when the user has no money left to bet or the user decides to quit.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help