homework and lab for matlab 243.docx

course material

homework and lab for matlab 243
EEC 243 Introduction to Programming – MATLABLab 5: Loop Statements and Vectorizing
CodeTasksExecute this script and be amazed by the results!You can try more points to get a
clearer picture, but it may take a while to run.It is good programming style to always use a
for loop when the number of times to repeat the action is known.The following code uses a
while loop that mimics what a for loop should do.Re-write it using a for loop that
accomplishes exactly the same thing.Write a script that will prompt the user for a quiz
grade and error-check until the user enters a valid quiz grade.The script will then echo print
the grade.For this case, valid grades are in the range from 0 to 10 in steps of 0.5.Do this by
creating a vector of valid grades and then use any or all in the condition in the while
loop.Write a script beautyofmath that produces the following output.The script should
iterate from 1 to 9 to produce the expressions on the left, perform the specified operation to
get the results shown on the right, and print exactly in the format shown here.(Optional)
Write a “Guess My Number Game― program.The program generates a random integer
in a specified range, and the user (the player) has to guess the number.The program allows
the use to play as many times as he/she would like; at the conclusion of each game, the
program asks whether the player wants to play again.clearclfx = rand;y = rand;plot(x,y)hold
onfor it = 1:10000choic = round(rand*2);if choic == 0x = x/2;y = y/2;elseif choic == 1x =
(x+1)/2;y = y/2;elsex = (x+0.5)/2;y = (y+1)/2;endplot(x,y,’r*’)hold onendmyprod =
1;i = 1;while i <= 4num = input(‘Enter a number: ‘);myprod = myprod * num;i = i +
1;endAnswer:Answer:>> beautyofmath1 x 8 + 1 = 912 x 8 + 2 = 98123 x 8 + 3 = 9871234 x 8
+ 4 = 987612345 x 8 + 5 = 98765123456 x 8 + 6 = 9876541234567 x 8 + 7 =
987654312345678 x 8 + 8 = 98765432123456789 x 8 + 9 = 987654321Answer:The basic
algorithm is:The program starts by printing instructions on the screen.For every game:After
all games have been played, print a summary showing the average number of guesses.the
program generates a new random integer in the range from MIN to MAX.Treat MIN and
MAX like constants; start by initializing them to 1 and 100loop to prompt the player for a
guess until the player correctly guesses the integerfor each guess, the program prints
whether the player’s guess was too low, too high, or correctat the conclusion (when the
integer has been guessed):print the total number of guesses for that gameprint a message
regarding how well the player did in that game (e.g the player took way too long to guess
the number, the player was awesome, etc.).To do this, you will have to decide on ranges for
your messages and give a rationale for your decision in a comment in the
program.Assignment 5Prompt the user for an integer n and print “MATLAB rocks!― n
times.Given the following loop:Trace this to determine the output, and then enter it to verify
your answer.Write code that will prompt the user for 5 numbers, and store them in a
vector.Make sure that you preallocate the vector!Write a function myones that will receive
two input arguments n and m and will return an n by m matrix of all ones.Do NOT use any
built-in functions (so, yes, the code will be inefficient).Answer:while x < 10actionendFor
what values of the variable x would the action of the loop be skipped entirely?If the variable
x is initialized to have the value of 5 before the loop, what would the action have to include
in order for this to not be an infinite loop?Answer:Answer:for i = 2:2:6fprintf(‘%d: ‘, i)for j =
i:-1:1fprintf(‘*’)endfprintf(‘n’)endAnswer:Answer:Answer:myones.m

Recomendados

CPP Homework Help por
CPP Homework HelpCPP Homework Help
CPP Homework HelpC++ Homework Help
75 vistas19 diapositivas
JavaScript 101 por
JavaScript 101JavaScript 101
JavaScript 101Mindy McAdams
5.4K vistas23 diapositivas
CS1160 Spring 2014 Introduction to ProgrammingCoin Toss Simu.docx por
CS1160 Spring 2014 Introduction to ProgrammingCoin Toss Simu.docxCS1160 Spring 2014 Introduction to ProgrammingCoin Toss Simu.docx
CS1160 Spring 2014 Introduction to ProgrammingCoin Toss Simu.docxfaithxdunce63732
8 vistas5 diapositivas
Build tic tac toe with javascript (3:28) por
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Thinkful
1.3K vistas49 diapositivas
Phase 4 Problem Solving with LoopsTotal orderDescriptionOnce .docx por
Phase 4 Problem Solving with LoopsTotal orderDescriptionOnce .docxPhase 4 Problem Solving with LoopsTotal orderDescriptionOnce .docx
Phase 4 Problem Solving with LoopsTotal orderDescriptionOnce .docxrandymartin91030
4 vistas9 diapositivas
Python Homework Help por
Python Homework HelpPython Homework Help
Python Homework HelpPython Homework Help
4 vistas11 diapositivas

Más contenido relacionado

Similar a homework and lab for matlab 243.docx

python notes.pdf por
python notes.pdfpython notes.pdf
python notes.pdfRohitSindhu10
45 vistas89 diapositivas
python 34💭.pdf por
python 34💭.pdfpython 34💭.pdf
python 34💭.pdfAkashdeepBhattacharj1
4 vistas89 diapositivas
Csci101 lect08a matlab_programs por
Csci101 lect08a matlab_programsCsci101 lect08a matlab_programs
Csci101 lect08a matlab_programsElsayed Hemayed
13 vistas21 diapositivas
I need help with this assignment. Please include comments throughout.pdf por
I need help with this assignment. Please include comments throughout.pdfI need help with this assignment. Please include comments throughout.pdf
I need help with this assignment. Please include comments throughout.pdfshanhairstonkirui643
5 vistas3 diapositivas
C++ programming exercise por
C++ programming exerciseC++ programming exercise
C++ programming exercisekhapul
302 vistas7 diapositivas
CSCE 1030 Homework Assignment 3 Due 1159 PM on Sunday,.docx por
CSCE 1030 Homework Assignment 3  Due 1159 PM on Sunday,.docxCSCE 1030 Homework Assignment 3  Due 1159 PM on Sunday,.docx
CSCE 1030 Homework Assignment 3 Due 1159 PM on Sunday,.docxmydrynan
3 vistas19 diapositivas

Similar a homework and lab for matlab 243.docx(20)

I need help with this assignment. Please include comments throughout.pdf por shanhairstonkirui643
I need help with this assignment. Please include comments throughout.pdfI need help with this assignment. Please include comments throughout.pdf
I need help with this assignment. Please include comments throughout.pdf
C++ programming exercise por khapul
C++ programming exerciseC++ programming exercise
C++ programming exercise
khapul302 vistas
CSCE 1030 Homework Assignment 3 Due 1159 PM on Sunday,.docx por mydrynan
CSCE 1030 Homework Assignment 3  Due 1159 PM on Sunday,.docxCSCE 1030 Homework Assignment 3  Due 1159 PM on Sunday,.docx
CSCE 1030 Homework Assignment 3 Due 1159 PM on Sunday,.docx
mydrynan3 vistas
CSCE 1030 Homework Assignment 3 Due 1159 PM on Sunday,.docx por Jack632244
CSCE 1030 Homework Assignment 3  Due 1159 PM on Sunday,.docxCSCE 1030 Homework Assignment 3  Due 1159 PM on Sunday,.docx
CSCE 1030 Homework Assignment 3 Due 1159 PM on Sunday,.docx
Jack6322440 vistas
Java Guessing Game Number Tutorial por OXUS 20
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
OXUS 202.5K vistas
You will write a multi-interface version of the well-known concentra.pdf por FashionColZone
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
FashionColZone2 vistas
DO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS.pdf por adamsapparelsformen
DO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS.pdfDO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS.pdf
DO NOT USE THE ANSWERS ON OTHER CHEGG ANSWERS TO ANSWER THIS.pdf
Python programming workshop session 2 por Abdul Haseeb
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
Abdul Haseeb99 vistas
Python programing por hamzagame
Python programingPython programing
Python programing
hamzagame144 vistas
I need help with this program and I have the code for this p.pdf por adianantsolutions
I need help with this program and I have the code for this p.pdfI need help with this program and I have the code for this p.pdf
I need help with this program and I have the code for this p.pdf
Ecs 10 programming assignment 4 loopapalooza por JenniferBall44
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
JenniferBall44183 vistas
A01 por lksoo
A01A01
A01
lksoo368 vistas
Java programming lab assignments por rajni kaushal
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
rajni kaushal3.3K vistas
For this assignment- you will write a C++ program that asks the user t.docx por EvanY5VMacLeodq
For this assignment- you will write a C++ program that asks the user t.docxFor this assignment- you will write a C++ program that asks the user t.docx
For this assignment- you will write a C++ program that asks the user t.docx
EvanY5VMacLeodq3 vistas

Más de scottharry3

What are your thoughts on how the war in Ukraine.docx por
What are your thoughts on how the war in Ukraine.docxWhat are your thoughts on how the war in Ukraine.docx
What are your thoughts on how the war in Ukraine.docxscottharry3
14 vistas1 diapositiva
Step Draft your Goals Begin by reading page.docx por
Step Draft your Goals Begin by reading page.docxStep Draft your Goals Begin by reading page.docx
Step Draft your Goals Begin by reading page.docxscottharry3
5 vistas1 diapositiva
Stock Repurchases In the short article Dutch Shell Finally.docx por
Stock Repurchases In the short article Dutch Shell Finally.docxStock Repurchases In the short article Dutch Shell Finally.docx
Stock Repurchases In the short article Dutch Shell Finally.docxscottharry3
2 vistas1 diapositiva
What common goals did American gay and lesbian.docx por
What common goals did American gay and lesbian.docxWhat common goals did American gay and lesbian.docx
What common goals did American gay and lesbian.docxscottharry3
2 vistas1 diapositiva
While resetting Asus Router you must have to follow.docx por
While resetting Asus Router you must have to follow.docxWhile resetting Asus Router you must have to follow.docx
While resetting Asus Router you must have to follow.docxscottharry3
3 vistas1 diapositiva
What is your biggest nutrition Is it eating.docx por
What is your biggest nutrition Is it eating.docxWhat is your biggest nutrition Is it eating.docx
What is your biggest nutrition Is it eating.docxscottharry3
3 vistas1 diapositiva

Más de scottharry3(20)

What are your thoughts on how the war in Ukraine.docx por scottharry3
What are your thoughts on how the war in Ukraine.docxWhat are your thoughts on how the war in Ukraine.docx
What are your thoughts on how the war in Ukraine.docx
scottharry314 vistas
Step Draft your Goals Begin by reading page.docx por scottharry3
Step Draft your Goals Begin by reading page.docxStep Draft your Goals Begin by reading page.docx
Step Draft your Goals Begin by reading page.docx
scottharry35 vistas
Stock Repurchases In the short article Dutch Shell Finally.docx por scottharry3
Stock Repurchases In the short article Dutch Shell Finally.docxStock Repurchases In the short article Dutch Shell Finally.docx
Stock Repurchases In the short article Dutch Shell Finally.docx
scottharry32 vistas
What common goals did American gay and lesbian.docx por scottharry3
What common goals did American gay and lesbian.docxWhat common goals did American gay and lesbian.docx
What common goals did American gay and lesbian.docx
scottharry32 vistas
While resetting Asus Router you must have to follow.docx por scottharry3
While resetting Asus Router you must have to follow.docxWhile resetting Asus Router you must have to follow.docx
While resetting Asus Router you must have to follow.docx
scottharry33 vistas
What is your biggest nutrition Is it eating.docx por scottharry3
What is your biggest nutrition Is it eating.docxWhat is your biggest nutrition Is it eating.docx
What is your biggest nutrition Is it eating.docx
scottharry33 vistas
When you hear the word what are the first.docx por scottharry3
When you hear the word what are the first.docxWhen you hear the word what are the first.docx
When you hear the word what are the first.docx
scottharry33 vistas
Summary of the type of risk management plan you selected.docx por scottharry3
Summary of the type of risk management plan you selected.docxSummary of the type of risk management plan you selected.docx
Summary of the type of risk management plan you selected.docx
scottharry35 vistas
What is the purpose of the statement of cash.docx por scottharry3
What is the purpose of the statement of cash.docxWhat is the purpose of the statement of cash.docx
What is the purpose of the statement of cash.docx
scottharry36 vistas
When determining how to allocate resources in a hospital how.docx por scottharry3
When determining how to allocate resources in a hospital how.docxWhen determining how to allocate resources in a hospital how.docx
When determining how to allocate resources in a hospital how.docx
scottharry33 vistas
Students will submit a research paper comparing and contrasting 2.docx por scottharry3
Students will submit a research paper comparing and contrasting 2.docxStudents will submit a research paper comparing and contrasting 2.docx
Students will submit a research paper comparing and contrasting 2.docx
scottharry33 vistas
Students must choose 3 Principles Of Technology.docx por scottharry3
Students must choose 3 Principles Of Technology.docxStudents must choose 3 Principles Of Technology.docx
Students must choose 3 Principles Of Technology.docx
scottharry33 vistas
What are some unique challenges we face in the.docx por scottharry3
What are some unique challenges we face in the.docxWhat are some unique challenges we face in the.docx
What are some unique challenges we face in the.docx
scottharry33 vistas
Week 7 Assignment Case Dynamic Pricing Strategies.docx por scottharry3
Week 7 Assignment Case Dynamic Pricing Strategies.docxWeek 7 Assignment Case Dynamic Pricing Strategies.docx
Week 7 Assignment Case Dynamic Pricing Strategies.docx
scottharry37 vistas
Strategic Marketing Metrics The owners of The Westside Coffee.docx por scottharry3
Strategic Marketing Metrics The owners of The Westside Coffee.docxStrategic Marketing Metrics The owners of The Westside Coffee.docx
Strategic Marketing Metrics The owners of The Westside Coffee.docx
scottharry37 vistas
Week 5 ProjectAssignment Due February 14 at PMCourse.docx por scottharry3
Week 5 ProjectAssignment Due February 14 at PMCourse.docxWeek 5 ProjectAssignment Due February 14 at PMCourse.docx
Week 5 ProjectAssignment Due February 14 at PMCourse.docx
scottharry33 vistas
Week 7 Discussion Please separate by discussions as Discussion.docx por scottharry3
Week 7 Discussion Please separate by discussions as Discussion.docxWeek 7 Discussion Please separate by discussions as Discussion.docx
Week 7 Discussion Please separate by discussions as Discussion.docx
scottharry33 vistas
Week 2 ProjectAssignment Due May 10 at AM Initial.docx por scottharry3
Week 2 ProjectAssignment Due May 10 at AM Initial.docxWeek 2 ProjectAssignment Due May 10 at AM Initial.docx
Week 2 ProjectAssignment Due May 10 at AM Initial.docx
scottharry33 vistas
Week 6 Assignment 1 Learning Developing an Employee.docx por scottharry3
Week 6 Assignment 1 Learning Developing an Employee.docxWeek 6 Assignment 1 Learning Developing an Employee.docx
Week 6 Assignment 1 Learning Developing an Employee.docx
scottharry34 vistas
Systematic reviews are an umbrella term for a number of.docx por scottharry3
Systematic reviews are an umbrella term for a number of.docxSystematic reviews are an umbrella term for a number of.docx
Systematic reviews are an umbrella term for a number of.docx
scottharry33 vistas

Último

The Accursed House by Émile Gaboriau por
The Accursed House  by Émile GaboriauThe Accursed House  by Émile Gaboriau
The Accursed House by Émile GaboriauDivyaSheta
201 vistas15 diapositivas
Ch. 7 Political Participation and Elections.pptx por
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptxRommel Regala
97 vistas11 diapositivas
Are we onboard yet University of Sussex.pptx por
Are we onboard yet University of Sussex.pptxAre we onboard yet University of Sussex.pptx
Are we onboard yet University of Sussex.pptxJisc
96 vistas7 diapositivas
Java Simplified: Understanding Programming Basics por
Java Simplified: Understanding Programming BasicsJava Simplified: Understanding Programming Basics
Java Simplified: Understanding Programming BasicsAkshaj Vadakkath Joshy
295 vistas155 diapositivas
Sociology KS5 por
Sociology KS5Sociology KS5
Sociology KS5WestHatch
70 vistas23 diapositivas
Dance KS5 Breakdown por
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 BreakdownWestHatch
79 vistas2 diapositivas

Último(20)

The Accursed House by Émile Gaboriau por DivyaSheta
The Accursed House  by Émile GaboriauThe Accursed House  by Émile Gaboriau
The Accursed House by Émile Gaboriau
DivyaSheta201 vistas
Ch. 7 Political Participation and Elections.pptx por Rommel Regala
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptx
Rommel Regala97 vistas
Are we onboard yet University of Sussex.pptx por Jisc
Are we onboard yet University of Sussex.pptxAre we onboard yet University of Sussex.pptx
Are we onboard yet University of Sussex.pptx
Jisc96 vistas
Sociology KS5 por WestHatch
Sociology KS5Sociology KS5
Sociology KS5
WestHatch70 vistas
Dance KS5 Breakdown por WestHatch
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 Breakdown
WestHatch79 vistas
AI Tools for Business and Startups por Svetlin Nakov
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
Svetlin Nakov107 vistas
UWP OA Week Presentation (1).pptx por Jisc
UWP OA Week Presentation (1).pptxUWP OA Week Presentation (1).pptx
UWP OA Week Presentation (1).pptx
Jisc88 vistas
Community-led Open Access Publishing webinar.pptx por Jisc
Community-led Open Access Publishing webinar.pptxCommunity-led Open Access Publishing webinar.pptx
Community-led Open Access Publishing webinar.pptx
Jisc93 vistas
Create a Structure in VBNet.pptx por Breach_P
Create a Structure in VBNet.pptxCreate a Structure in VBNet.pptx
Create a Structure in VBNet.pptx
Breach_P75 vistas
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively por PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 585 vistas
11.30.23 Poverty and Inequality in America.pptx por mary850239
11.30.23 Poverty and Inequality in America.pptx11.30.23 Poverty and Inequality in America.pptx
11.30.23 Poverty and Inequality in America.pptx
mary850239160 vistas
Classification of crude drugs.pptx por GayatriPatra14
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra1486 vistas
Narration ppt.pptx por TARIQ KHAN
Narration  ppt.pptxNarration  ppt.pptx
Narration ppt.pptx
TARIQ KHAN135 vistas
When Sex Gets Complicated: Porn, Affairs, & Cybersex por Marlene Maheu
When Sex Gets Complicated: Porn, Affairs, & CybersexWhen Sex Gets Complicated: Porn, Affairs, & Cybersex
When Sex Gets Complicated: Porn, Affairs, & Cybersex
Marlene Maheu67 vistas
JiscOAWeek_LAIR_slides_October2023.pptx por Jisc
JiscOAWeek_LAIR_slides_October2023.pptxJiscOAWeek_LAIR_slides_October2023.pptx
JiscOAWeek_LAIR_slides_October2023.pptx
Jisc96 vistas
REPRESENTATION - GAUNTLET.pptx por iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood100 vistas
AUDIENCE - BANDURA.pptx por iammrhaywood
AUDIENCE - BANDURA.pptxAUDIENCE - BANDURA.pptx
AUDIENCE - BANDURA.pptx
iammrhaywood84 vistas

homework and lab for matlab 243.docx

  • 1. homework and lab for matlab 243 EEC 243 Introduction to Programming – MATLABLab 5: Loop Statements and Vectorizing CodeTasksExecute this script and be amazed by the results!You can try more points to get a clearer picture, but it may take a while to run.It is good programming style to always use a for loop when the number of times to repeat the action is known.The following code uses a while loop that mimics what a for loop should do.Re-write it using a for loop that accomplishes exactly the same thing.Write a script that will prompt the user for a quiz grade and error-check until the user enters a valid quiz grade.The script will then echo print the grade.For this case, valid grades are in the range from 0 to 10 in steps of 0.5.Do this by creating a vector of valid grades and then use any or all in the condition in the while loop.Write a script beautyofmath that produces the following output.The script should iterate from 1 to 9 to produce the expressions on the left, perform the specified operation to get the results shown on the right, and print exactly in the format shown here.(Optional) Write a “Guess My Number Game― program.The program generates a random integer in a specified range, and the user (the player) has to guess the number.The program allows the use to play as many times as he/she would like; at the conclusion of each game, the program asks whether the player wants to play again.clearclfx = rand;y = rand;plot(x,y)hold onfor it = 1:10000choic = round(rand*2);if choic == 0x = x/2;y = y/2;elseif choic == 1x = (x+1)/2;y = y/2;elsex = (x+0.5)/2;y = (y+1)/2;endplot(x,y,’r*’)hold onendmyprod = 1;i = 1;while i <= 4num = input(‘Enter a number: ‘);myprod = myprod * num;i = i + 1;endAnswer:Answer:>> beautyofmath1 x 8 + 1 = 912 x 8 + 2 = 98123 x 8 + 3 = 9871234 x 8 + 4 = 987612345 x 8 + 5 = 98765123456 x 8 + 6 = 9876541234567 x 8 + 7 = 987654312345678 x 8 + 8 = 98765432123456789 x 8 + 9 = 987654321Answer:The basic algorithm is:The program starts by printing instructions on the screen.For every game:After all games have been played, print a summary showing the average number of guesses.the program generates a new random integer in the range from MIN to MAX.Treat MIN and MAX like constants; start by initializing them to 1 and 100loop to prompt the player for a guess until the player correctly guesses the integerfor each guess, the program prints whether the player’s guess was too low, too high, or correctat the conclusion (when the integer has been guessed):print the total number of guesses for that gameprint a message regarding how well the player did in that game (e.g the player took way too long to guess the number, the player was awesome, etc.).To do this, you will have to decide on ranges for your messages and give a rationale for your decision in a comment in the program.Assignment 5Prompt the user for an integer n and print “MATLAB rocks!― n
  • 2. times.Given the following loop:Trace this to determine the output, and then enter it to verify your answer.Write code that will prompt the user for 5 numbers, and store them in a vector.Make sure that you preallocate the vector!Write a function myones that will receive two input arguments n and m and will return an n by m matrix of all ones.Do NOT use any built-in functions (so, yes, the code will be inefficient).Answer:while x < 10actionendFor what values of the variable x would the action of the loop be skipped entirely?If the variable x is initialized to have the value of 5 before the loop, what would the action have to include in order for this to not be an infinite loop?Answer:Answer:for i = 2:2:6fprintf(‘%d: ‘, i)for j = i:-1:1fprintf(‘*’)endfprintf(‘n’)endAnswer:Answer:Answer:myones.m