REC04_Problems_Solutions

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

This preview shows pages 1–4. 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-ﬁle 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 ﬁle 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 ﬁrst, 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) 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 )

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

View Full Document
This is the end of the preview. Sign up to access the rest of the 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.

### Page1 / 12

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

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online