final_review

# final_review - end end end 4 The following 3 files are...

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

Review For Final ENGR 3 1. What is printed by the following MATLAB code? x = [ 1 2 2 3 2 1 1 2]; f = [ 0 0 0 ]; for ctr = 1:8 f( x(ctr) ) = f( x(ctr) ) + 1; end for ctr = 1:3 fprintf( 'f(%d) = %d\n', ctr, f(ctr) ); end 2. The following MatLab code finds the area underneath a curve and prints it's value. Draw a graph showing the area which is calculated. Area = 0; intv = .001; for x = 0 : intv : 1999*intv Area = Area + (x^2 + 2)*intv; end for x = 2 : intv : 2 + 1999*intv Area = Area + ( 8-x )*intv; end fprintf( 'Area under curve is %f\n', Area); 1

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

View Full Document
3. What is printed by the following MATLAB code? fee = 22/7; error = 2; for D = 1 : 4 for N = 3*D : 4*D - 1 approx = N/D; if abs(approx - fee) < error error = abs(approx - fee); fprintf('N = %d, D = %d\n', N, D);
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: end end end 4. The following 3 files are named exam10.m, f1.m, and f2.m. All are stored in the same directory. What is printed when exam10 is executed? %This file is named exam10.m for a = 0.4 fprintf( '%d', f1(a, a+1)); end % This file is named f1.m function f1out = f1(x,y) if x+y <= 3 f1out = f2( x+y ); else f1out = f2( x ) + f2( y ); end % This file is named f2.m function f2out = f2(z) if ( z <= 2 ) f2out = z; else f2out = z*(z-1); end 2 5. What is printed by the following MATLAB code? for x = 0:3 a( x+1 ) = 1.1*(x^2); end for y = 0:3 b( y+2 ) = a( mod(y+1, 4) + 1) + ceil( a(y+1) ); end for i = 1:length(b) fprintf( '%.2f ', b(i) ); end 3...
View Full Document

## This note was uploaded on 08/06/2010 for the course ENGR 3 taught by Professor Ben-yaakov during the Summer '08 term at UCSB.

### Page1 / 3

final_review - end end end 4 The following 3 files are...

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

View Full Document
Ask a homework question - tutors are online