REC04_Problems_Solutions

# REC04_Problems_Solutions - 1 14:440:127 Introduction to...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 4. Write the code above in an M-file and save it as firstMLfile.m on your J: drive, in the MATLAB Files Directory. Make sure to add the J: drive to MatLab’s path. Edit the code above to display the values of x , y , before and after they are swapped. Then run your file by typing firstMLfile in the command window. Answer: x = 56; y = 87; disp(x) disp(y) temp = x; x = y; y = temp; disp(x) disp(y) 5. On a piece of paper, predict the outcome of the following MatLab calculations, and then test your predictions in MatLab: 5^2*3 5^(2*3) (1+3+5)/(5+3+1) Answer: % respectively: 75 15625 1 6. Use MatLab to calculate the square root of 2+3^4 , without using the function sqrt first, and then using the sqrt function. Answer: % Recall that a square root is a 1/2 power. (2+3^4) ^ (1/2) % or (2+3^4) ^ (0.5) % or sqrt(2+3^4) 7. Create a variable r , set it equal to 10 . Calculate the area and circumference of a circle with radius r. Answer: r = 10; circumference = pi*(2*r); area = pi*r^2;
3 8. For all of the following problems, set x = 15 , y = 22 , and z = 35 . First, on a piece of paper, predict the results by hand. Then, test your predictions on MatLab: (a) x>22 & y>22 Answer: false ANDalse false 0 (b) x>22 | y>22 Answer: false OR false false 0 (c) ~0 Answer: NOT false true 1 (d) ~z Answer: (recall that non-zero is true) NOT true false 0 (e) x + y > 37 Answer: 37>37 false 0 (f) x + ( y > 37 ) Answer: x + (false) 15 + (0) 15 (g) x - y | 0 Answer: (recall that non-zero is true) 15 - 22 | 0 -7 | 0 true | false true 1 (h) y>x & z>y & z>34 Answer: 22>15 & 35>22 & 35>34 true & true & true

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 true & true true 1 (i) x>3 & x<5 Answer:
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern