Engineering 25 Problems 1.[23, 26] Solutions Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege.edu Engineering-25: Computational Methods 1 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt P1.23 FT approximation Consider the Step Function 1 for f x 1 for 0 x 0 x The Fourier Transform 4 k sin 2k 1x f x for the k 1 2k 1 above Function Taking the First FOUR Terms of the Infinite Sum 4 sin x sin 3 x sin 5 x sin 7 x f x 1 3 5 7 Engineering-25: Computational Methods 2 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt P.1-23 FT m-file & plot % Bruce Mayer, PE % EGNR25 * 23Jun11 % file = P1_23_fft_1106.m % delx = 1e-6 % for small increment on either side of ZERO % % Make STEP-function plotting vector x1 = [-pi,0-delx, 0+delx, pi] f1 = [-1,-1,1,1] % % Make FFT plotting vectors x2 =-pi:0.01:pi; % Row Vector Containing 629 elements % Calc the value of f at all 629 points using elementby-element addition f2 = (4/pi)*(sin(x2)/1 + sin(3*x2)/3 + sin(5*x2)/5 + sin(7*x2)/7); % % Plot Both with a grid plot(x1,f1, x2,f2, 'linewidth',3), grid 1.5 1 0.5 0 -0.5 -1 -1.5 -4 -3 -2 -1 Engineering-25: Computational Methods 3 0 1 2 3 4 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt P1.23 MATLAB m-file % Bruce Mayer, PE % EGNR25 * 23Jan11 % file = P1_23_fft_1201.m % % delx = 1e-6 % for small increment on either side of ZERO % % Make STEP-function plotting vector x1 = [-pi,0-delx, 0+delx, pi] f1 = [-1,-1,1,1] % % Make FFT plotting vectors x2 =-pi:0.01:pi; f2 = (4/pi)*(sin(x2)/1 + sin(3*x2)/3 + sin(5*x2)/5 + sin(7*x2)/7); % % Plot Both with a grid plot(x1,f1, x2,f2, 'linewidth',3), grid, title('Vectorized Solution') % disp('Showing NONLoop plot; hit ANY KEY to continue') pause % % % try using FOR Loop and element-by-element addition to calc components of the FT fTot = zeros(1, length(x2)); % initialize total as array of zeros same length of x2 for k = 1:2:7 fc = sin(k*x2)/k; fTot = fTot + fc; % element-by-element addition end % % Now mult fTot Vector by 4/pi to create f3 f3= (4/pi)*fTot; % % use same x2 as before to plot f3 plot(x1,f1, x2,f3, 'linewidth',3), grid, title('Loop and zeros Solution') Engineering-25: Computational Methods 4 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt P1.23 MATLAB Plots Vectorized Solution 1.5 1 0.5 0 -0.5 -1 -1.5 -4 -3 -2 -1 0 1 2 3 4 Loop and zeros Solution 1.5 1 0.5 0 -0.5 -1 -1.5 -4 -3 -2 -1 Engineering-25: Computational Methods 5 0 1 2 3 4 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt P1-26 Law of CoSines Given Irregular Quadrilateral By Law of CoSines a b c 2b1c1 cos A1 2 a b c 2b2c2 cos A2 2 2 1 2 2 Engineering-25: Computational Methods 6 2 1 2 2 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt P1-26 Law of CoSines Given Quantities Find c2 when b1 = 180 m b2 = 165 m c1 = 115 m A1 = 120° A2 = 100° • Instructor to WhtBd to Build Quadratic Eqn in c2 Engineering-25: Computational Methods 7 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt P1-26 Law of CoSines Build Quadratic Eqn in c2 • Instructor to Write m-file from Scratch (start w/ blank m-file) Engineering-25: Computational Methods 8 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt P1-26 mFile & Results % Bruce Mayer, PE % EGNR25 * 23Jun11 % file = P1_26_LawOfCos_1106.m % % % Set Known ParaMeters b1 = 180; b2 = 165; c1 = 115; % all in meters A1 = 120; A2 = 100; % all in Degrees % % Calc the constant a^2 asq = b1^2 + c1^2 -2*b1*c1*cosd(A1) % note use of cosd % % Make Quadratic PolyNomial c2Poly = [1, -2*b2*cosd(A2), (b2^2 - asq)] % % Find roots of PolyNomial c2roots = roots(c2Poly) % % NOTE: since c2 is a DISTANCE it MUST be POSITIVE asq = 66325 c2Poly = 1.0e+004 * 0.0001 0.0057 -3.9100 c2roots = -228.4542 171.1503 ANSWER Engineering-25: Computational Methods 9 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt Another Solution % Bruce Mayer, PE % 20Aug12 * ENGR25 % file P1_26_LawOfCos_Alternative_1208.m % % Side Lengths in meters b1 = 180, b2 = 165, c1 = 115 % commas do NOT suppress ReadBack % % Angles in Degrees A1 = 120; A2 = 100; % semicolons DO suppress ReadBack % % calc parameter "asqd" asqd = b1^2 + c1^2 - 2*b1*c1*cosd(A1) % note use of cosd; not cos. cos operates on radians % c2QuadCoeff = [1 -2*b2*cosd(A2) b2^2-asqd] % find Roots of Quadratic c2 = roots(c2QuadCoeff) % Note that c2 is a DISTANCE and hence MUST be POSITIVE Engineering-25: Computational Methods 10 Bruce Mayer, PE ENGR-25_Prob_9_3_Solution.ppt