MatlabIntro
.pdf
keyboard_arrow_up
School
University of Florida *
*We aren’t endorsed by this school
Course
2217
Subject
Computer Science
Date
Feb 20, 2024
Type
Pages
6
Uploaded by erikanoel34 on coursehero.com
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. % Radius is inputted and the area and circumference are calculated
radius = 4; area = pi*radius.^2;
disp(
'area ='
); disp(area);
area =
50.2655
circum = 2*pi*radius;
disp(
'circumference ='
); disp(circum);
circumference =
25.1327
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.
% Radius is inputted and the surface area and volume are calculated
radius = 4;
surf_area = 4*pi*radius.^2;
disp(
'surface area ='
); disp(surf_area);
surface area =
201.0619
volume = (4/3)*pi*radius.^3;
disp(
'volume ='
); disp(volume);
volume =
268.0826
Problem 3
Plot tan(x) from 3π/2 to 3π/2. 1
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.
x = linspace(3*pi/2, 3*pi/2, 1000); % Generate x values from 3*pi/2 to 3*pi/2
y = tan(x); % Calculate corresponding y values for tan(x)
plot(x, y); % Plot tan(x)
axis([-3*pi/2 3*pi/2 -10 10]); % Set axis ranges
xlabel(
'x - \pi'
); % Label x-axis
ylabel(
'tan(x)'
); % Label y-axis
title(
'Plot of tan(x) from 3\pi/2 to 3\pi/2'
); % Title of the plot
Loop Homework - Problem 4
2
•
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.
clc,clear %
%% Dice Game Under and Over Seven prompt=
"How much money are you starting with: "
;
player_1=input(prompt);
% The game will run 10 times, which is enough time for the user to quit the
% game or lose
for k=1:10
if player_1<= 0
caution=(
"You need to start the game with more than 0 : "
);
player_1=input(caution);
%Here are some parameters such that the user chooses a starting amount
%greater than zero.
else
player_1=player_1;
end
placed_bet=
"Place your bet on Under 7, Over 7, or Exactly 7: "
;
3
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
Related Questions
Window 1Should have a welcome message, a textbox to receive AN EXISTING ID of the user and a button to access the data base. All users ID should be saved in a data base (Don’t use access). Once the Id is verified then the program will give the user access to the main menu window.Your database should have the following columns.
arrow_forward
Create a folder named MyTestFiles and insert into it four text files named mytest1.txt, mytest2.txt, mytest3.txt, and mytest4.txt. Insert at least 10 lines of some text into each file.
arrow_forward
Write a GUI-based program that allows the user to open, edit, and save text files. The GUI should include a labeled entry field for the filename and a multiline text widget for the text of the file. The user should be able to scroll through the text by manipulating a vertical scrollbar. Include command buttons labeled Open, Save, and New that allow the user to open, save, and create new files. The New command should then clear the text widget and the entry widget.
arrow_forward
Extra 6-1 Develop the Temperature Converter
In this exercise, you’ll use radio buttons to determine whether the conversion is from Fahrenheit to Celsius or vice versa. You’ll also modify the DOM so the labels change when a radio button is clicked, and the page displays an error message when the user enters invalid data.
1. Open the application in this folder:
exercises_extrach06convert_temps
2. Note that the JavaScript file has some starting JavaScript code, including the $() function, three helper functions, three event handler functions, and a DOMContentLoaded event handler that attaches the three event handlers.
3. Review how the toCelsius() and toFarhenheit() event handler functions call the toggleDisplay() helper function and pass it strings to display. Also note that the toggleDisplay() helper function and the convertTemp() event handler function are incomplete.
4. Code the toggleDisplay() function so it changes the text in the labels for the text boxes to the values in the…
arrow_forward
Open the application in the folder under the coursework.
Open the HTML file and notice that an Invoice Date field has been added. Then, open the HTML file and notice that it includes a getFormattedDate() function that formats the Date object that’s passed to it in MM/DD/YYYY format and then returns the date string.
Start the application, enter a subtotal, and click the Calculate button. Note that nothing is displayed in the Invoice Date field.
In the click() event handler for the Calculate button, add code that gets the current date and formats it using the getFormattedDate() function. Then, add code that provides a default value of the formatted current date for the invoice date. Note that if an invoice date is entered, that date isn’t validated.
Add code that sets the value of the Invoice Date field. If you’ve done this right, the application should display the current date when you click the Calculate button without entering anything in the Invoice Date field.
<!DOCTYPE…
arrow_forward
*
aut
cad
Realtime and point consider are sub-commands for the main command
pan.
True
False
*
aut
cad
Zoom command is one of the drawing menu commands used to control
the size of the view, zoom in and out in the AutoCAD program.
False
True
arrow_forward
o Second Column: Align the contents to the center.
Insert the image with a filename "c.png".
. Insert the text "REGISTER AN COURSE ACCOUNT ". Set the font color
as purple and face as arial. Add the symbol at the end using a
code.
. Insert a button with a value "REGISTER HERE". Use the event
onmouseout to execute a function.
Create a function that allows the user to enter the course
registration
Student ID, Course Selected, Mobile Number.
details as follows: Student Name, Email address,
Display the result using the alert () function.
arrow_forward
Create blade template containing a form having thefollowing form controls: case and submit button. After thevalue of the case field is filled by the user, an appropriateresponse should be generated. For example, if user enters1, the result should be “First Case” and so on. You have touse switch case directive to complete this task
arrow_forward
The edit menu choices serve what purpose?
arrow_forward
Plotting assignment
Create 4 subplots of y = x, y2 = x², y3 = x³, and y4 =
Vx. Use 10 points between x =
red circles, y2 = x2 use green dashes, y3 = x3 use blue
triangles, and y4 = Vx use black squares. Also, give each
subplot a title. Include a command to save the figure as a
PNG file so that it can be imported into another program
such as Microsoft PowerPoint.
0 to x:
10. For y1
= x use
Show me the figure on the PNG file
arrow_forward
Select the correct command, term, or option.
This term describes a predesigned file with formatting and graphical elements on which you can base a file; using a template is a quick way to create a
Choose..
professional-looking file (document, presentation, spreadsheet, or database).
This term describes an interface element that contains a variety of options and commands that allow you to manage your files and perform tasks such as
Choose.
saving and printing.
Use this button to return to an open file from the backstage area.
Choose.
Click this tab to display the backstage area.
Choose..
The name of the open file displays on this area at the top of the workbook.
Choose.
Click this button to display the previous folder level.
Choose.
A OneDrive account or USB flash drive is an example of this, which is the place you save a file on the computer.
Choose.
This part of the file should be descriptive of the file contents so you can easily find the file you need.
Choose..
Click this option in…
arrow_forward
Your document will undergo a rewriting by QuillBot. You may enter anything here by typing it out or pasting it, and then pressing the Enter button.
arrow_forward
MM Image Processing Project
Use your own images that are different than the images in the tutorial file.Include in your report the following only:
1) all the commands producing images,
2) the images produced, and
3) comment briefly on every image showing what was done and describe the result.
All commands and comments MUST BE IN TEXT (NOT IMAGES).You may modify the filters and show the result as well.Compile all commands text that you used in an appendix.Save your WORD file as PDF as well.
arrow_forward
The file needed is the second screenshot posted.
arrow_forward
5. Zip your folder then submit only the zipped file on blackboard.
arrow_forward
Please help
2. The idea is to create a file upload form where we can define the final file name ourselves. This file name is taken from the input text box which is also in the form. Once submitted, immediately display the file in a web browser using the <img> tag. Please create this simple code using laravel, the image below is the desired final look.
arrow_forward
Save : You'll use this command to create a copy of a document while
keeping the original. When you use Save As, you'll need to choose a
different name and/or location for the copied version.
O True
O False
Word includes different options for customizing a table, including adding
rows or columns and changing the table style.
O True
False
If there is text you want to move from one area of the document to
another. you can copy and paste or drag and drop the text.
O True
False
arrow_forward
5-Redo Command:This command will
undo the effects of the last
command. You can reach this
command by going to the Quick
Access toolbar and clicking the Undo
button. If you want to undo several
commands, click the small arrow at
the right. You will see a list of the
commands; select the group :and
undo them Also, you can type u at
the command window (don't type
undo, because it has a different
meaning), or press Ctrl + Z at the
keyboard.
TURE
FULSE
arrow_forward
Set the keyPress event.
arrow_forward
Create a new javascript file called cart.js and make a product object for each of your products and store it in a products array when the script loads. Create an empty array to store the items added to the cart.
Program the "add to cart button" to take the product id, finds the product object in the products array and adds it to the items added to cart array.
Program the "remove from cart button" to take the product id and remove the project object from the items purchased array.
Existing code:
<!DOCTYPE html><html>
<head>
<div id="product1" class="card"><img src="img/clorox.jpg"><h1>Clorox</h1><p class="price">$20.00</p><p>Household Cleaner</p><p><button id="product1Btn1">Add to Cart</button></p><p><button id="product1Btn2">Remove from Cart</button></p></div>
<div id="product2" class="card"><img src="img/oxiclean.jpg"><h1>Oxiclean</h1><p…
arrow_forward
Question 8
Write the command that displays all the lines containing a letter followed immediately by a number.
Use the editor to format your answer
Question 9
Show the two ways we can perform command substitution for the following command "Is -I "
You need to use the variable $VAR1 for the same.
Use the editor to format your answer
arrow_forward
6. Please use the "shared folder" option within VirtualBox and successfully transfer a file.
Please include images from the host machine and your target machine.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L
Related Questions
- Window 1Should have a welcome message, a textbox to receive AN EXISTING ID of the user and a button to access the data base. All users ID should be saved in a data base (Don’t use access). Once the Id is verified then the program will give the user access to the main menu window.Your database should have the following columns.arrow_forwardCreate a folder named MyTestFiles and insert into it four text files named mytest1.txt, mytest2.txt, mytest3.txt, and mytest4.txt. Insert at least 10 lines of some text into each file.arrow_forwardWrite a GUI-based program that allows the user to open, edit, and save text files. The GUI should include a labeled entry field for the filename and a multiline text widget for the text of the file. The user should be able to scroll through the text by manipulating a vertical scrollbar. Include command buttons labeled Open, Save, and New that allow the user to open, save, and create new files. The New command should then clear the text widget and the entry widget.arrow_forward
- Extra 6-1 Develop the Temperature Converter In this exercise, you’ll use radio buttons to determine whether the conversion is from Fahrenheit to Celsius or vice versa. You’ll also modify the DOM so the labels change when a radio button is clicked, and the page displays an error message when the user enters invalid data. 1. Open the application in this folder: exercises_extrach06convert_temps 2. Note that the JavaScript file has some starting JavaScript code, including the $() function, three helper functions, three event handler functions, and a DOMContentLoaded event handler that attaches the three event handlers. 3. Review how the toCelsius() and toFarhenheit() event handler functions call the toggleDisplay() helper function and pass it strings to display. Also note that the toggleDisplay() helper function and the convertTemp() event handler function are incomplete. 4. Code the toggleDisplay() function so it changes the text in the labels for the text boxes to the values in the…arrow_forwardOpen the application in the folder under the coursework. Open the HTML file and notice that an Invoice Date field has been added. Then, open the HTML file and notice that it includes a getFormattedDate() function that formats the Date object that’s passed to it in MM/DD/YYYY format and then returns the date string. Start the application, enter a subtotal, and click the Calculate button. Note that nothing is displayed in the Invoice Date field. In the click() event handler for the Calculate button, add code that gets the current date and formats it using the getFormattedDate() function. Then, add code that provides a default value of the formatted current date for the invoice date. Note that if an invoice date is entered, that date isn’t validated. Add code that sets the value of the Invoice Date field. If you’ve done this right, the application should display the current date when you click the Calculate button without entering anything in the Invoice Date field. <!DOCTYPE…arrow_forward* aut cad Realtime and point consider are sub-commands for the main command pan. True False * aut cad Zoom command is one of the drawing menu commands used to control the size of the view, zoom in and out in the AutoCAD program. False Truearrow_forward
- o Second Column: Align the contents to the center. Insert the image with a filename "c.png". . Insert the text "REGISTER AN COURSE ACCOUNT ". Set the font color as purple and face as arial. Add the symbol at the end using a code. . Insert a button with a value "REGISTER HERE". Use the event onmouseout to execute a function. Create a function that allows the user to enter the course registration Student ID, Course Selected, Mobile Number. details as follows: Student Name, Email address, Display the result using the alert () function.arrow_forwardCreate blade template containing a form having thefollowing form controls: case and submit button. After thevalue of the case field is filled by the user, an appropriateresponse should be generated. For example, if user enters1, the result should be “First Case” and so on. You have touse switch case directive to complete this taskarrow_forwardThe edit menu choices serve what purpose?arrow_forward
- Plotting assignment Create 4 subplots of y = x, y2 = x², y3 = x³, and y4 = Vx. Use 10 points between x = red circles, y2 = x2 use green dashes, y3 = x3 use blue triangles, and y4 = Vx use black squares. Also, give each subplot a title. Include a command to save the figure as a PNG file so that it can be imported into another program such as Microsoft PowerPoint. 0 to x: 10. For y1 = x use Show me the figure on the PNG filearrow_forwardSelect the correct command, term, or option. This term describes a predesigned file with formatting and graphical elements on which you can base a file; using a template is a quick way to create a Choose.. professional-looking file (document, presentation, spreadsheet, or database). This term describes an interface element that contains a variety of options and commands that allow you to manage your files and perform tasks such as Choose. saving and printing. Use this button to return to an open file from the backstage area. Choose. Click this tab to display the backstage area. Choose.. The name of the open file displays on this area at the top of the workbook. Choose. Click this button to display the previous folder level. Choose. A OneDrive account or USB flash drive is an example of this, which is the place you save a file on the computer. Choose. This part of the file should be descriptive of the file contents so you can easily find the file you need. Choose.. Click this option in…arrow_forwardYour document will undergo a rewriting by QuillBot. You may enter anything here by typing it out or pasting it, and then pressing the Enter button.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage
- COMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE L
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L