Summary of Lab 1a {@(#) Sun Jan 12 19:24:39 2014 } $Id: summary.txt,v 1.9 2014/01/13 00:25:02 mike Exp $ Only need to start with 4. EXERCISE 4 1. Values of pi=3.1416; eps=2.2204e-16, realmax=1.7977e+308, 2.2251e-308 2. format long; pi=3.14159265358979 3. pi-3.1416=-7.3464e-06 4. a=1, b=1+eps, c=2, d=2+eps: what is diff in display? 5. Are a and b different? Is display telling you that? 6. Are c and d different? Explain 7. format long still doesn't give all precision of b 8. x=something 9. x^2= x^3= 10. theta= 11. sin(theta)= cos(theta)= theta is in radians 12. diff a1='sqrt(4)', a2=sqrt(4) 13. eval(a1), a3=5*eval(a1) 14. save 15. clear (workspace is empty) 16. load EXERCISE 5 1. meshPoints=linspace(-1,1,500); 2. meshPoints(53)=-0.79158 3. yes, clicking on it confirms its length=500 4. numel(meshPoints)=500 also 5. Plot of sin on [-1,1], 2 cycles 6. exer5.m reproduces earlier commands, starts off with comments, 4 commands EXERCISE 6 1. colVec2=[ 1.5708 7.0686 6.2832]' 2. colVec2=[0 .7071 1]' , are these the values you expect? 3. colVec3=[2 10.4142 10]' 4. ??? Error using ==> + Matrix dimensions must agree. 5. norm(colVec3) = 14.5759 6. colvec4 = mat1 * colVec1= [69 -51 126]' 7. mat1Transpose = mat1' = 1 7 4 3 -9 6 5 2 8 rowVec2 =[ 2 10.4142 10] 8. mat2 = 35 -10 62 -10 134 -10 62 -10 116 rowVec2 = [-65 -21 -85] dotProduct = 177.73 euclideanNorm = 1.2247 9. determinant=162, traceOfMat1=0 10. min(rowVec1) = -9 11. max(mat1) = 7 6 8 12. max(abs(colVec1)) = 9 13. single largest element of a matrix is max(max(A)) 14. All sums of magic(100) are 500050 including sum(diag(A)) and sum(diag(fliplr(A))) 15. integers = 0 1 2 3 4 5 6 7 8 9 squareIntegers = integers * integers ??? Error using ==> * Inner matrix dimensions must agree. squareIntegers = 0 1 4 9 16 25 36 49 64 81 cubeIntegers = 0 1 8 27 64125 216 343 512 729 fourthIntegers = 0 1 16 81 256 625 1296 2401 4096 6561 tableOfPowers = 0 0 0 0 1 1 1 1 2 4 8 16 3 9 27 81 4 16 64 256 5 25 125 625 6 36 216 1296 7 49 343 2401 8 64 512 4096 9 81 729 6561 16. squareIntegers = integers .^ 2 = same values, norm(difference)=0 17. squaresPlus1 = [1 2 5 10 17 26 37 50 65 82] 18. squareIntegers ./ squaresPlus1 = 0 0.5 0.8 0.9 0.94118 0.96154 0.97297 0.98 0.98462 0.9878 squareIntegers / squaresPlus1 = 0.98146 19. tableOfCubes = 0 0 1 1 2 8 3 27 4 64 5 125 6 216 7 343 8 512 9 729 tableOfOddCubes = 1 1 3 27 5 125 7 343 9 729 tableOfEvenFourths = 0 0 2 16 4 256 6 1296 8 4096 20. AUL=A(1:5,1:5), AUR=A(1:5,6:10), ALR=A(6:10,6:10), ALL=A(6:10,1:5) 21. norm(A-B)=0 EXERCISE 7 1. v=[ -5 2 0 6 8 -1 -3 -10 -10]; 2. length(v)=9, agrees with visual count 3. execute code, norm=10 4. first value nrm=5 5. "largest value up to now" executed 3 times 6. all vals nrm=5,6,8,10 7. final value nrm=10 EXERCISE 8 1-2. exer8a.m + name and date comments at beginning 3. v = [-35 -20 38 49 4 -42 -9 0 -44 -34]; 4. norm=49 5. exer8b.m + name and date 6. norm=102.09 first 4 vals= 1225 1625 3069 5470 7. nothing EXERCISE 9 1-3. infinity_norm.m + comments, semicolon to stop printing nrm 4. help infinity_norm 5. infinity_norm(v) is 49 6. two_norm.m 7. aInfinity = 49 bTwo = 83.863 8. expression is "two_norm(a)+1/infinity_norm(b)" =111.53 EXERCISE 10 1. both_norms.m (normTwo=two_norm(v);) 2. [nrm,nrm2]=both_norms(b) prints nrm=42, nrm2=83.8630 3. both_norms(b) prints ans = 42 4. [~,nrm2]=both_norms(b) prints nrm2=83.8630 EXERCISE 11 1. exer11.m script m-file+ name and date 2. How is Matlab x related to x? 3. How is Matlab statement beginning y(k+1)= related to math? 4. What does clear do? 5. Use help to understand plot, hold, axis 6. execute exer11 EXERCISE 12 (extra 8) 1. straight loop, columns not aligned. 2. use fprintf to get rightmost digit aligned fprintf('The square root of %5d is %5d\n',i^2,i) 3. tangent: align decimal fprintf('The tangent of %5d is %12.4e\n',i^2,tan(i^2)) fprintf('The tangent of %3d is %10f\n',i^2,tan(i^2)); 5. exp: align decimal fprintf('The exponential of %3d is %-13.4e\n',i^2,exp(i^2)); (need right justify to get that pesky e+111 right)