E7_Su2010_Solutions4_all

E7_Su2010_Solutions4_all - 7/14/2010 Homework 4 Solutions...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework 4 Solutions Contents Problem 1 (a) (b) (c) (d) (e) Problem 2 Problem 3 (a) (b) Problem 4 Problem 5 Problem 1 (a) for k = 1:10 disp(k^2) end 1 4 9 16 25 36 49 64 81 100 (b) for k = 20:-1:13 disp(log(k)) end 2.9957 2.9444 2.8904 2.8332 2.7726 2.7081 2.6391 7/14/2010 Homework 4 Solutions C:/…/lab4soln.html 1/8
Background image of page 1

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

View Full DocumentRight Arrow Icon
2.5649 (c) The my_factorial function must use a for loop. type my_factorial function nfac = my_factorial(n) nfac = 1; for k = 1:n nfac = nfac*k; end As announced on bSpace, they should test their my_factorial function on the following values: my_factorial(0) ans = 1 my_factorial(1) ans = 1 my_factorial(5) ans = 120 my_factorial(10) ans = 3628800 (d) Many students used their my_factorial function in this part, but we told them that they could also use the built-in factorial function. The assignment does not explicitly ask for a for loop, so it's okay if they solved it another way, as long as it's correct. 7/14/2010 Homework 4 Solutions C:/…/lab4soln.html 2/8
Background image of page 2
exp_app function expApprox = exp_app(x,N) expApprox = 1; for n = 1:N expApprox = expApprox + x^n/factorial(n); end x = 2; N = [1 2 4 8 10]; approx = zeros(1,5); for k = 1:5 approx(k) = exp_app(x,N(k)); end plot(N,approx) (e) Create a magic square of order 6. They don't really need to explain what a magic square is or what significance it has. A = magic(6);
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/14/2010 for the course E 7 taught by Professor Patzek during the Summer '08 term at Berkeley.

Page1 / 8

E7_Su2010_Solutions4_all - 7/14/2010 Homework 4 Solutions...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online