340 likes | 728 Views
MATLAB Environment. ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne. Course Outline. MATLAB Intro Ch 1 MATLAB Environment Ch 2 Predefined Functions Ch 3 Plotting Ch 4 Programming Ch 5 Control Structures Ch 5 Matrix Computations Ch 6. Test #3. Test #4.
E N D
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
Course Outline • MATLAB • Intro Ch 1 • MATLAB Environment Ch 2 • Predefined Functions Ch 3 • Plotting Ch 4 • Programming Ch 5 • Control Structures Ch 5 • Matrix Computations Ch 6 Test #3 Test #4 206_M2
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_M2
Problem-Solving • An Engineering Problem-Solving Methodology • Problem Statement • Input/Output Description • Hand Example • Algorithm Development • Testing 206_M2
Example • Temperature Analysis • Problem Statement • Compute the average of a set of temperatures, then plot the time and temperature values. • Input/Output Description Average Temperature Time Values Plot of Time andTemperature Values Temperature Values 206_M2
Example • Hand Example • Average = (105 +126 +119)/3 = 116.67 Degrees F • Algorithm Development (outline) • Input times and temperatures • Compute average • Plot times and temperatures 206_M2
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_M2
Example • Testing 206_M2
Example 206_M2
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, ... 135, 136, 132, 137]; 206_M2
Example 206_M2
MATLAB Windows 206_M2
MATLAB Windows • Current Directory Window • Command Window • Command History • Workspace Window • Document Window • Array Editor • Graphics Window • Editor Window • Start Button 206_M2
Precedence 2 3 4 Scalar Operations • Exponentiation ^ • Multiplication * • Division / • Addition + • Subtraction - 206_M2
Expressions num = x^3 - 2*x^2 + x - 6.3; den = x^2 + 0.05*x - 3.14; f = num/den; 206_M2
Arrays, Vectors and Matrices • Row Vector • X = [1 2 3 4]; (1x4) • Column Vector • Y = [1; 2; 3; 4]; (4x1) • Y = [1 2 3 4]'; 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_M2
Array Operations • Arrays with Scalars • Same • Arrays with Arrays • Same for Addition and Subtraction • Element-by-Element Operations • Exponentiation .^ • Multiplication .* • Division ./ 206_M2
Number Display • Scientific Notation • LightSpeed = 2.99792e08; • Display Format • format long • format long e • format short • format short e • format bank • format + 206_M2
Saving Your Work • Saving Variables • Save the contents of the Workspace Window to a file • Default format binary .mat • save <file_name> • load <file_name> • ASCII (text) .dat • save <file_name> <variable_list> -ascii • load <file_name> • Script M-Files • ASCII (text) .m • MATLAB Editor Window • % This is a comment 206_M2
Problem Solving Applied • UDF Engine Performance • Problem Statement • Calculate the velocity and acceleration using a script M-file • Input/Output Description Start Time = 0 sec Velocity Final Time = 120 sec Acceleration Time Increment = 10 sec 206_M2
Problem Solving Applied • Hand Example • velocity = 0.00001 time3 - 0.00488 time2 + 0.75795 time + 181.3566 • acceleration = 3 - 0.000062 velocity2 • For time = 100 sec • velocity = 218.35 m/sec • acceleration = 0.04404 m/sec2 • Algorithm Development (outline) • Define time matrix • Calculate velocity and acceleration • Output results in table 206_M2
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 = 0.00001*time.^3 - 0.00488*time.^2 ... + 0.75795*time + 181.3566; %Use calculated velocities to find the acceleration acceleration = 3 - 6.2e-5*velocity.^2; %Present the results in a table [time', velocity', acceleration'] 206_M2
Testing 206_M2
Summary • MATLAB Environment • Scalar Operations • Array Operations • Saving Your Work • End of Chapter Summary • MATLAB Summary • Characters, Commands and Functions • Key Terms 206_M2