ENGR-25_TYU_chp02.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer Engr/Math/Physics 25 Test Your Understanding Chp02
ENGR-25_TYU_chp02.ppt 2 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T2.1-2 The B Matrix B = >> C = max(B) C = >> D = max(C) D = 25 >> C = sort(B) C = Ans (a) Ans (b)
ENGR-25_TYU_chp02.ppt 3 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T2.4-1 & T2.4-2 >> u = [6, -8, 3]; >> w = [5; 3; -4]; >> u u = >> w w = >> u*w ans = -6 >> P = [7,4; -3,2; 5,9]; >> Q = [1,8; 7,6]; >> % [P][Q] = [3x2][2x2] >> P*Q ans =
ENGR-25_TYU_chp02.ppt 4 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T2.5-4 >> f = [6,4,0,-5];g = [12,-7,3,9]; >> f2 = polyval(f,2) f2 = 59 >> g = polyval(g,2) g = 83 >> f2/g2 ans = >> quot2 = polyval(f,2)/polyval (g,2) quot2 = >> [q,r] = deconv(f,g); >> quot2 = polyval(q,2)+polyval (r,2)/polyval(g,2) quot2 =
ENGR-25_TYU_chp02.ppt 5 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T2.5-5 >> x = [-7:.02:1]; >> f = [1,13,52,6]; >> FofX = polyval(f,x); >> plot(x, FofX), xlabel('x'), ylabel('f(x)'), grid
ENGR-25_TYU_chp02.ppt 6 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T2.6-1 The Script File The Output % TYU T2.6-1 % Bruce Mayer, PE % ENGR25 20Jun05 A{1} = [1:4]; A{2} = [0,9,2]; A{3} = [2:5]; A{4} = [6:8]; [x,y] = deal(A{1:2}); B = [x,y] C = [A{2};A{4}] [u,v] = deal(A{2:3}); D = min([u,v]) B = C = D = 0
ENGR-25_TYU_chp02.ppt 7 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T2.7-1 m-File
ENGR-25_TYU_chp02.ppt 8 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T2.7-1 Exercise Structure >> student(3).tests ans = >> student(3).tests(2) = 53; >> student(3).tests ans = >> student(1).IDN ans = >> student student = 1x3 struct array with fields: name IDN tests >> new_student = rmfield(student,'IDN'); >> new_student new_student = 1x3 struct array with fields: name tests >> new_student(1).IDN ??? Reference to non-existent field 'IDN'. >> student(1:3).name ans = Nolan Ryan ans = Walter Johnson ans = Bob Gibson
ENGR-25_TYU_chp02.ppt 9 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T1.3-3 Command Script From the Command Window >> t = [0:0.1:5]; >> s = 2*sin(3*t +2) + sqrt(5*t +1); >> plot(t,s), xlabel('t (seconds)'), ylabel('s (fps)'), title('Speed vs Time - ENGR25 Jun05')
ENGR-25_TYU_chp02.ppt 10 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T1.3-3: File → Save As...jpg
ENGR-25_TYU_chp02.ppt 11 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods T1.3-4 Command Script From the Command Window >> x = [0:0.02:1.5]; >> y = 4*sqrt(6*x + 1); >> z = 5*exp(0.3*x) - 2*x; >> plot(x,y,x,z), xlabel('distance (m)'), ylabel('force (N)'), gtext('y'), gtext('z')