This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 1 14:440:127 Introduction to Computers for Engineers Recitation 06 Problems - Pertaining to LEC06 Notes Rutgers University, Spring 2011 Instructor - Brenda V. Cortez INSTRUCTIONS: If you want, you can create a separate M-file for each of the problems in your recitation problem sets, so that you can reference back to your answers later when you study. Save all your work to your MATLAB Files directory in the J: Drive. An alternative to separate M-Files, is to create a single M-file for all the problems, and use %% to create a cell for each problem. Refer to my Video Tutorial on the topic of program cells found in Video Tutorials > LEC04 Video Tutorials . For all problems, always think about using good variable names, even if the problem doesnt explicitly specify them; get used to defining your own. Make sure you go through all the problems before the exam and ask any questions if you dont understand why something works the way it does. I suggest that you write simple pseudocode stating the algorithm you will use to solve each problem, before you start coding it. This will save you making simple errors. PROBLEMS: 1. Vectorize the following code using an arbitrary value for NUM . t = 0; for k=1:NUM t = t + k; end 2. Write a for loop that prints out the decimal equivalent of the reciprocals: 1/2, 1/3, 1/4, ... , 1/19, 1/20 . Then, write this without using a loop, vectorize , and use tic/toc to see which is faster. 3. Vectorize the following code using an arbitrary value for something . p = 1; for k=1:something p = p * k; end disp(p) 4. Find the sum of the geometric series: 1 + 2^1 + 2^2 +...+ 2^10 using a for loop. Then, rewrite this without using a loop, vectorize , and use tic/toc to see which is faster. 2 5. Vectorize the following code using an arbitrary value for ending . g = 0; for k=1:length(ending) g = g+ ending(k); end disp(g) 6. Display the values of x 3 for all positive integer values x such that x 2 is less than 2000 ....
View Full Document
This note was uploaded on 03/30/2011 for the course ENGINEERIN 127 taught by Professor Finch during the Spring '08 term at Rutgers.
- Spring '08