{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Recitation 02 Problems- Solutions

# Recitation 02 Problems- Solutions - 14:440:127 Introduction...

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

14:440:127 Introduction to Computers for Engineers Recitation 2- Problems for students to attempt Please complete these problems on your own time if you do not finish in recitation. You don’t need to show us the completed recitation problems, although we recommending saving a copy of your solutions for your own benefit. 1) Write Matlab code that displays “You must go to study right away” if the variable TVTime equals 1. if (TVTime==1) disp( 'You must go to bed!' ) end 2) Create a row vector containing the even numbers 2 through 18, a column vector containing 1,5,9,…,25,29, and a 3*3 matrix A full of zeros . v1 = 2:2:18; v2 = transpose(1:4:29); A = zeros(3); 3) Create a 3 x 4 matrix in which all the elements have a value of pi. Then, change all elements in the 2nd row to -pi. Finally, display the sine of each value in the matrix. z = ones(3,4) * pi; [r c] = size(z); %% this is the more general way of doing this problem: z(2,:) = -pi * ones(1,c); sin(z) 4) Evaluate the following Matlab Expressions by hand. Verify in Matlab: a. 2 + round(6/9 + 3*2)/2 - 3 2+round(6.6666)/2 – 3 2+7/2 – 3 2.5 b. 3^2+ceil(6/9+3)/2 – 3 3^2+ceil(3.6666)/2 – 3 9 + 4/2 – 3 8 c. 3^2+floor(6/9+3)/2 -3 3^2+floor(3.6666)/2 – 3 9 + 3/2 – 3 7.5 d. 3^2+fix(6/9+3)/2 -3 3^2+fix(3.6666)/2 – 3 9 + 3/2 – 3 7.5 5) Ask the user to input a number, and then display whether that number is odd or even.

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

View Full Document