E7Midterm 2 Solutions 2010(2)

E7Midterm 2 Solutions 2010(2) - Contents Problem 1 Problem...

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

View Full Document Right Arrow Icon
Contents Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 Problem 7 Problem 8 Problem 9 format compact Problem 1 for i = 1:20 for j = 1:10 A(i,j) = sin(i*pi/4)*cos(j*pi/3); end end Problem 2 z = func2(3) z = 3 4 2 1 Problem 3 p = 3.5; q = 2; k = -5.5; p3i = (p + q) >= k p3iii = (p > q) || p < q p3iv = p + (q >= k) p3i = 1 p3ii =
Background image of page 1

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

View Full DocumentRight Arrow Icon
0 p3iii = 1 p3iv = 4.5000 Problem 4 u = [-3 0 0 2 5]; v = [-3 -2 0 2 4]; u < 0 v == u ans = 1 0 0 0 0 ans = 1 0 1 1 0 Problem 5 %two different examples of a correct solution are given below. type func3 function y = func3(month) switch lower(month) case {'january' 'march' 'may' 'july' 'august'. .. 'october' 'december'} y = 31; case {'april' 'june' 'september' 'november'} y = 30; case 'february' y = 28; otherwise error('not a valid month') end
Background image of page 2
Problem 6 type rec_sum3 function [Sn] = rec_sum3(n) if n == 1 Sn = 1; else Sn = rec_sum3(n-1) + n^3; end Problem 7 a7 = eps(1) < eps(100) b7 = eps(-1) < eps(1)
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 01/27/2011 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 5

E7Midterm 2 Solutions 2010(2) - Contents Problem 1 Problem...

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