ENGR1121 – Computing Applications in Mechanical Engineering
Lab Iteration: While Loops
Lab due: end of lab
Total points: 20
Labs are to be individual work. You may use MATLAB Marina, MATLAB’s help, and your notes. Lab work will be
graded during lab time and working results must be shown to the lab instructor by the end of the scheduled
lab time. All MATLAB programs and functions must be completed and submitted in accordance with the
Computing Assignment Format and the MATLAB Coding Style. Submit an electronic copy of your lab work to
the appropriate Dropbox Folder in GSU’s Folio by the end of lab. No hard copy needed unless specifically
requested by the instructor.
Grading
Each problem will be graded according to: program design (identifying inputs/givens, process, and outputs;
algorithm) and program style (program comments, variable names, proper formatted input and output
including units) 25%, and program correctness 75%.
Lab Work
1. (5 points) Write a MATLAB program using while loops to do the following. Although you will probably see
ways to solve these problems without iteration, you must use it for all these solutions.
a. Display numbers from 1,2,3…till the user-defined max value N=50.
b. Display numbers from 50, 49, 48,…as long as all are positive numbers.
c. Display only even numbers from 2,4,6,…till the user-defined max value of N=50.
d. Create a vector x with odd numbers 1,3,5,…till the user-defined max value of N=99.
e. Create a vector y with its elements as cube of its indices: 1,8,27,…till the user-defined max value of
1000000.
2. (9 points) Write a MATLAB program that will perform the following operations on an array of data v.
Create the array v = [-13.5 2.5 -32.0 45.0 -23.0 4.25 0.0 0.85 10.0 -1.5] using direct entry.
a) Using iteration (while loop), iterate over the indices of the array v and create a new array w whose
values are the corresponding values in v divided by the index of the element.
b) Using iteration (while loop), iterate over the indices of the array v and create a new array y whose
values are the corresponding values in v squared. Do this one element at a time starting at the first
one. Stop the iteration when the element is greater than 10. The remaining values in y should be the
same as those in v.
c) Using iteration (while loop), iterate over the indices of the array v and create a new array boolGTZ
whose values are true if the corresponding value of v is positive and false otherwise. Do this one
element at a time starting at the first one as long as the element is not zero. Stop the iteration when
the element is zero. Note that the length of the Boolean vector may not be the same as that of v.
3. (6 points) Write a MATLAB program to determine how many terms, N, are required for partial sum
=
f
N
=
f
∑ 5k 2 − 2k of the infinite series
k =1
∞
∑ 5k
k =1
2
− 2k to not exceed 10000. Use iteration (while loop) and
scalar operations. The program should display the number of terms and the value of f for that number of
terms. Do not use element by element operations on arrays or MATLAB’s built in sum function for this.
1
Instructor: Dr. Priya Goeser
Lab Iteration: While Loops
of 1
Report
Tell us what’s wrong with it:
Thanks, got it!
We will moderate it soon!
Struggling with your assignment and deadlines?
Let EduBirdie's experts assist you 24/7! Simply submit a form and tell us what you need help with.
Free up your schedule!
Our EduBirdie Experts Are Here for You 24/7! Just fill out a form and let us know how we can assist you.
Take 5 seconds to unlock
Enter your email below and get instant access to your document