ENGR1121 – Computing Applications in Mechanical Engineering
Lab Iteration: For 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 for 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….50
b) Display numbers from 50, 49, 48,…1
c) Display only even numbers from 2,4,6,…50
d) Create a vector x with odd numbers 1,3,5,…99 as its elements
e) Create a vector y with its elements as cube of its indices: 1,8,27,….1000000
2. (6 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 (for 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 (for loop), iterate over the data of the array v and create a new array y whose values
are the corresponding values in v squared.
c) Using iteration (for 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.
3. (5 points) Write a MATLAB program to compute an approximation of the infinite series using N=15 terms
=
f
∞
∑ 5k
k =1
2
− 2k .
a) Use iteration (for loop) and scalar operations. Do not use element by element operations on
arrays or MATLAB’s built in sum function.
b) Use element by element operations on arrays and MATLAB’s built in sum function to verify
your answer to part (a).
4. (4 points) The elements of the symmetric Pascal matrix are obtained from:
Pmn =
(m + n − 2)!
(m − 1)!(n − 1)!
Write a MATLAB program that uses iteration to create an n x n symmetric Pascal matrix. Use the program
to create 4 x 4 and 7 x 7 Pascal matrices. Use the built-in MATLAB function pascal to check your work.
1
Instructor: Dr. Priya Goeser
Lab Iteration: For 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