CE108-Spring2006-Final

# CE108-Spring2006-Final - CE108/Johnson Final Exam Spring...

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

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

View Full Document

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

View Full Document
CE108/Johnson Final Exam Spring 2006 7 May 2008 1/7 Instructions : Name : ____________________ 1) Write your name / initials in the place(s) provided. 2) Please write neatly and legibly. Problem 1 (20 points) Program Execution a. What are the values of the variables after the following code is run: clear; a = 1:3:11; a = ____________ b = a(a(1)+1); b = ____________ c = a(length(a)); c = ____________ d = a(end:-1:1); d = ____________ tmp = linspace(100,200,300); e = tmp(1); e = ____________ f = length(tmp); f = ____________ g = tmp(end); g = ____________ h = ones(3,4); h = ____________ k=h; k([1 3],[1 4])=0; k = ____________ b. The function m-file f1.m has the code below: function y = f1(x) y = 0; while x>0 y = y + x; for i = 1:2:x if i ~= 3 y = y – 1; end if rem(y,2) == 0 break end end x = x – 2 end Then, if you type the following expressions at M ATLAB ’s command line, what will the result be? f1(1) f1(0.2) f1(4)
Initials 7 May 2008 2/7 c. The function m-file f2.m has the code below: function b = f2(n) b = []; while n>0 m = rem(n,2); b = [m b]; n = (n-m) / 2; end Then, if you type the following expressions at M ATLAB ’s command line, what will the result be? f2(5) f2(13) f2(127) In general, what does this function do? The variable names ( i.e. , “b”, “m” and “n”) are not descriptive. To what would you change them in order to make them more descriptive? d. The function m-file f3.m has the code below: function b = f3(x) b = []; for k = 1:length(x) if x(k) b = [b k]; end end

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 10/21/2008 for the course CE 108 taught by Professor Johnson during the Spring '08 term at USC.

### Page1 / 10

CE108-Spring2006-Final - CE108/Johnson Final Exam Spring...

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

View Full Document
Ask a homework question - tutors are online