homework and lab for matlab 243.docx

4

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
46 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
305 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
khapul305 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 Haseeb100 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
JenniferBall44184 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 4934bk

You are the information technology manager of an.docx por
You are the information technology manager of an.docxYou are the information technology manager of an.docx
You are the information technology manager of an.docx4934bk
6 vistas2 diapositivas
Write an essay using one of the poems in the.docx por
Write an essay using one of the poems in the.docxWrite an essay using one of the poems in the.docx
Write an essay using one of the poems in the.docx4934bk
4 vistas1 diapositiva
Writing in the social sciences.docx por
Writing in the social sciences.docxWriting in the social sciences.docx
Writing in the social sciences.docx4934bk
2 vistas1 diapositiva
Writing and and Neurology Departments By.docx por
Writing and and Neurology Departments By.docxWriting and and Neurology Departments By.docx
Writing and and Neurology Departments By.docx4934bk
3 vistas2 diapositivas
Writing Premium Paper Help.docx por
Writing Premium Paper Help.docxWriting Premium Paper Help.docx
Writing Premium Paper Help.docx4934bk
3 vistas1 diapositiva
You will be required to interview a business manager of.docx por
You will be required to interview a business manager of.docxYou will be required to interview a business manager of.docx
You will be required to interview a business manager of.docx4934bk
4 vistas1 diapositiva

Más de 4934bk(20)

You are the information technology manager of an.docx por 4934bk
You are the information technology manager of an.docxYou are the information technology manager of an.docx
You are the information technology manager of an.docx
4934bk6 vistas
Write an essay using one of the poems in the.docx por 4934bk
Write an essay using one of the poems in the.docxWrite an essay using one of the poems in the.docx
Write an essay using one of the poems in the.docx
4934bk4 vistas
Writing in the social sciences.docx por 4934bk
Writing in the social sciences.docxWriting in the social sciences.docx
Writing in the social sciences.docx
4934bk2 vistas
Writing and and Neurology Departments By.docx por 4934bk
Writing and and Neurology Departments By.docxWriting and and Neurology Departments By.docx
Writing and and Neurology Departments By.docx
4934bk3 vistas
Writing Premium Paper Help.docx por 4934bk
Writing Premium Paper Help.docxWriting Premium Paper Help.docx
Writing Premium Paper Help.docx
4934bk3 vistas
You will be required to interview a business manager of.docx por 4934bk
You will be required to interview a business manager of.docxYou will be required to interview a business manager of.docx
You will be required to interview a business manager of.docx
4934bk4 vistas
Your literature review should use all the articles from your.docx por 4934bk
Your literature review should use all the articles from your.docxYour literature review should use all the articles from your.docx
Your literature review should use all the articles from your.docx
4934bk7 vistas
You will continue to work on the SWOT analysis or.docx por 4934bk
You will continue to work on the SWOT analysis or.docxYou will continue to work on the SWOT analysis or.docx
You will continue to work on the SWOT analysis or.docx
4934bk3 vistas
Your final healthcare marketing and communication plan has been.docx por 4934bk
Your final healthcare marketing and communication plan has been.docxYour final healthcare marketing and communication plan has been.docx
Your final healthcare marketing and communication plan has been.docx
4934bk5 vistas
to questions.docx por 4934bk
to questions.docxto questions.docx
to questions.docx
4934bk2 vistas
You are a family nurse practitioner working in an outpatient.docx por 4934bk
You are a family nurse practitioner working in an outpatient.docxYou are a family nurse practitioner working in an outpatient.docx
You are a family nurse practitioner working in an outpatient.docx
4934bk3 vistas
You will first choose a behavioral scenario than the.docx por 4934bk
You will first choose a behavioral scenario than the.docxYou will first choose a behavioral scenario than the.docx
You will first choose a behavioral scenario than the.docx
4934bk3 vistas
You have an interview for a job as a paid.docx por 4934bk
You have an interview for a job as a paid.docxYou have an interview for a job as a paid.docx
You have an interview for a job as a paid.docx
4934bk3 vistas
Writing based on a newspaper article your choice such as.docx por 4934bk
Writing based on a newspaper article your choice such as.docxWriting based on a newspaper article your choice such as.docx
Writing based on a newspaper article your choice such as.docx
4934bk8 vistas
X have a positive or a negative impact on.docx por 4934bk
X have a positive or a negative impact on.docxX have a positive or a negative impact on.docx
X have a positive or a negative impact on.docx
4934bk2 vistas
Write an essay on the colonial.docx por 4934bk
Write an essay on the colonial.docxWrite an essay on the colonial.docx
Write an essay on the colonial.docx
4934bk3 vistas
Write about Theoretical Framework by providing guidelines and basic.docx por 4934bk
Write about Theoretical Framework by providing guidelines and basic.docxWrite about Theoretical Framework by providing guidelines and basic.docx
Write about Theoretical Framework by providing guidelines and basic.docx
4934bk3 vistas
Write about Mission Command.docx por 4934bk
Write about Mission Command.docxWrite about Mission Command.docx
Write about Mission Command.docx
4934bk3 vistas
Write about the GFOA rating category Operations.docx por 4934bk
Write about the GFOA rating category Operations.docxWrite about the GFOA rating category Operations.docx
Write about the GFOA rating category Operations.docx
4934bk2 vistas
Write about Korean drama especially the.docx por 4934bk
Write about Korean drama especially the.docxWrite about Korean drama especially the.docx
Write about Korean drama especially the.docx
4934bk3 vistas

Último

JRN 362 - Lecture Twenty-Two por
JRN 362 - Lecture Twenty-TwoJRN 362 - Lecture Twenty-Two
JRN 362 - Lecture Twenty-TwoRich Hanley
39 vistas157 diapositivas
Education of marginalized and socially disadvantages segments.pptx por
Education of marginalized and socially disadvantages segments.pptxEducation of marginalized and socially disadvantages segments.pptx
Education of marginalized and socially disadvantages segments.pptxGarimaBhati5
47 vistas36 diapositivas
Career Building in AI - Technologies, Trends and Opportunities por
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesWebStackAcademy
47 vistas44 diapositivas
Pharmaceutical Analysis PPT (BP 102T) por
Pharmaceutical Analysis PPT (BP 102T) Pharmaceutical Analysis PPT (BP 102T)
Pharmaceutical Analysis PPT (BP 102T) yakshpharmacy009
116 vistas29 diapositivas
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE... por
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...Nguyen Thanh Tu Collection
100 vistas91 diapositivas
Berry country.pdf por
Berry country.pdfBerry country.pdf
Berry country.pdfMariaKenney3
80 vistas12 diapositivas

Último(20)

JRN 362 - Lecture Twenty-Two por Rich Hanley
JRN 362 - Lecture Twenty-TwoJRN 362 - Lecture Twenty-Two
JRN 362 - Lecture Twenty-Two
Rich Hanley39 vistas
Education of marginalized and socially disadvantages segments.pptx por GarimaBhati5
Education of marginalized and socially disadvantages segments.pptxEducation of marginalized and socially disadvantages segments.pptx
Education of marginalized and socially disadvantages segments.pptx
GarimaBhati547 vistas
Career Building in AI - Technologies, Trends and Opportunities por WebStackAcademy
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy47 vistas
Pharmaceutical Analysis PPT (BP 102T) por yakshpharmacy009
Pharmaceutical Analysis PPT (BP 102T) Pharmaceutical Analysis PPT (BP 102T)
Pharmaceutical Analysis PPT (BP 102T)
yakshpharmacy009116 vistas
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE... por Nguyen Thanh Tu Collection
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
JQUERY.pdf por ArthyR3
JQUERY.pdfJQUERY.pdf
JQUERY.pdf
ArthyR3107 vistas
Creative Restart 2023: Leonard Savage - The Permanent Brief: Unearthing unobv... por Taste
Creative Restart 2023: Leonard Savage - The Permanent Brief: Unearthing unobv...Creative Restart 2023: Leonard Savage - The Permanent Brief: Unearthing unobv...
Creative Restart 2023: Leonard Savage - The Permanent Brief: Unearthing unobv...
Taste62 vistas
EILO EXCURSION PROGRAMME 2023 por info33492
EILO EXCURSION PROGRAMME 2023EILO EXCURSION PROGRAMME 2023
EILO EXCURSION PROGRAMME 2023
info33492208 vistas
Six Sigma Concept by Sahil Srivastava.pptx por Sahil Srivastava
Six Sigma Concept by Sahil Srivastava.pptxSix Sigma Concept by Sahil Srivastava.pptx
Six Sigma Concept by Sahil Srivastava.pptx
Sahil Srivastava51 vistas
Payment Integration using Braintree Connector | MuleSoft Mysore Meetup #37 por MysoreMuleSoftMeetup
Payment Integration using Braintree Connector | MuleSoft Mysore Meetup #37Payment Integration using Braintree Connector | MuleSoft Mysore Meetup #37
Payment Integration using Braintree Connector | MuleSoft Mysore Meetup #37
Nelson_RecordStore.pdf por BrynNelson5
Nelson_RecordStore.pdfNelson_RecordStore.pdf
Nelson_RecordStore.pdf
BrynNelson550 vistas
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx por Niranjan Chavan
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptxGuidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx
Niranjan Chavan42 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