DeGracia_Miguel_19481379_Section22_LabAssignment10

# DeGracia_Miguel_19481379_Section22_LabAssignment10 - % %%...

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

%% Miguel De Gracia. 19481379. Lab Assignment 10. Section 22. % %% Problem 1 % %On seperate sheet of paper. % %% Problem 2a % type gcd_rec t %% Problem 2b % type gcd_loop t gcd_rec(29,3) gcd_loop(29,3) gcd_rec(483,51) gcd_loop(483,51) gcd_rec(138346,11947) gcd_loop(138346,11947) g %% Problem 2c % n = 100:50:450; m = 1; m for j=n tic; gcd_rec(3*j,3); t_rec(m) = toc; m = m+1; end e m = 1; for j=n tic; gcd_loop(3*j,3); t_loop(m) = toc; m = m+1; end e %Code to plot using polyfit. % Rec = polyfit(t_rec,n,1); Loop = polyfit(t_loop,n,1); VRec = polyval(Rec,n); VLoop = polyval(Loop,n); plot(n,VRec,'k'); hold plot(n,VLoop,'r'); hold off h % It is evident since the slope of the recursive line is not only steeper % but its initial point is also much higher it can be concluded that it is % not as efficient as the iterative function.Although iterative functions

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

View Full Document
% are complex and hard to understand they are much more efficient than % recursive functions since they take longer.
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % %% Problem 3 % f = n; f while(f ~= 0) digit = rem(f,10); f = floor(f/10); disp(digit) end e type revint t revint(15601) revint(9834672) revint(1011) r %% Problem 4 % type pascal_row t pascal_row(10) pascal_row(20) p %% Problem 5a % %Since S(N+1) is the total number of moves for the first configuration, %we must sum the total number of moves in the following manner: %S(N) + 1 + S(N) = 2*S(N) + 1. This only makes sense due to the amount of %configurations there are.Therefore, S(N+1) = 2*S(N) + 1. % %% Problem 5b % type towersteps t towersteps(1) towersteps(2) towersteps(3) towersteps(10) towersteps(64) t %% Problem 5c % seconds_in_one_year = 60*60*24*365; end_of_world = (towersteps(64)) / seconds_in_one_year e %% Problem 5d % type towers t towers(3,1,2) towers(4,1,2) t %% Problem 6 % type elect t elect(1:7) elect(1:10) elect(1:57)...
View Full Document

## This note was uploaded on 02/18/2010 for the course ENGINEERIN 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

### Page1 / 3

DeGracia_Miguel_19481379_Section22_LabAssignment10 - % %%...

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

View Full Document
Ask a homework question - tutors are online