MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
206_M22 Course Outline MATLAB IntroCh 1 MATLAB EnvironmentCh 2 Predefined FunctionsCh 3 PlottingCh 4 ProgrammingCh 5 Control StructuresCh 5 Matrix ComputationsCh 6 Test #3 Test #4
206_M23 Computer Software Operating System Interface between user and hardware Application Software Word Processors, Spreadsheets, Databases,... Computer-aided Design (CAD) Mathematical Computation Tools (MATLAB) Computer Languages Machine Language Assembly Language High-level Languages (C++)
206_M24 Problem-Solving An Engineering Problem-Solving Methodology Problem Statement Input/Output Description Hand Example Algorithm Development Testing
206_M25 Example Temperature Analysis Problem Statement Compute the average of a set of temperatures, then plot the time and temperature values. Input/Output Description Time Values Temperature Values Average Temperature Plot of Time and Temperature Values
206_M26 Example Hand Example Average = ( )/3 = Degrees F Algorithm Development (outline) Input times and temperatures Compute average Plot times and temperatures Time (Minutes)Temperature (Degrees F)
206_M27 Example MATLAB Solution % Compute average temperature and % plot the temperature data. % time = [0.0, 0.5, 1.0]; temps = [105, 126, 119]; average = mean(temps) plot(time, temps), title('Temperature Measurements'), xlabel('Time, minutes'), ylabel('Temperature, degrees F'), grid
206_M28 Example Testing
206_M29 Example
206_M210 Example Testing time = [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0,... 3,5, 4.0, 4.5, 5.0]; temps = [105, 126, 119, 129, 132, 128, 131, , 136, 132, 137];
206_M211 Example
206_M212 MATLAB Windows
206_M213 MATLAB Windows Current Directory Window Command Window Command History Workspace Window Document Window Array Editor Graphics Window Editor Window Start Button
206_M214 Scalar Operations Exponentiation ^ Multiplication * Division / Addition + Subtraction - Precedence 2 3 4
206_M215 Expressions num = x^3 - 2*x^2 + x - 6.3; den = x^ *x ; f = num/den;
206_M216 Arrays, Vectors and Matrices Row Vector X = [ ]; (1x4) Column Vector Y = [1; 2; 3; 4]; (4x1) Y = [ ]'; transpose operator Matrix A = [1 2; 3 4; 5 6]; (3x2) Evenly Spaced Matrices B = [1:5]; C = [1:2:5]; D = linspace(1,10,3);
206_M217 Array Operations Arrays with Scalars Same Arrays with Arrays Same for Addition and Subtraction Element-by-Element Operations Exponentiation.^ Multiplication.* Division./
206_M218 Number Display Scientific Notation LightSpeed = e08; Display Format format long format long e format short format short e format bank format +
206_M219 Saving Your Work Saving Variables Save the contents of the Workspace Window to a file Default format binary.mat save load ASCII (text).dat save -ascii load Script M-Files ASCII (text).m MATLAB Editor Window % This is a comment
206_M220 Problem Solving Applied UDF Engine Performance Problem Statement Calculate the velocity and acceleration using a script M-file Input/Output Description Velocity Start Time = 0 sec Acceleration Final Time = 120 sec Time Increment = 10 sec
206_M221 Problem Solving Applied Hand Example velocity = time time time acceleration = velocity 2 For time = 100 sec velocity = m/sec acceleration = m/sec 2 Algorithm Development (outline) Define time matrix Calculate velocity and acceleration Output results in table
206_M222 MATLAB Solution clear, clc %Example 2.4 %These commands generate velocity and acceleration %values for a UDF aircraft test %Define the time matrix time = 0:10:120; %Calculate the velocity matrix velocity = *time.^ *time.^ *time ; %Use calculated velocities to find the acceleration acceleration = e-5*velocity.^2; %Present the results in a table [time', velocity', acceleration']
206_M223 Testing
206_M224 Summary MATLAB Environment Scalar Operations Array Operations Saving Your Work End of Chapter Summary MATLAB Summary Characters, Commands and Functions Key Terms