matlab environment
DESCRIPTION
MATLAB Environment. ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne. 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. - PowerPoint PPT PresentationTRANSCRIPT
MATLAB Environment
ELEC 206
Computer Applications for Electrical Engineers
Dr. Ron Hayne
206_M2 2
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 3
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 4
Problem-Solving
An Engineering Problem-Solving Methodology Problem Statement Input/Output Description Hand Example Algorithm Development Testing
206_M2 5
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 andTemperature Values
206_M2 6
Example
Hand Example
Average = (105 +126 +119)/3 = 116.67 Degrees F Algorithm Development (outline)
Input times and temperaturesCompute averagePlot times and temperatures
Time (Minutes) Temperature (Degrees F)
0.0 105
0.5 126
1.0 119
206_M2 7
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 8
Example
Testing
206_M2 9
Example
206_M2 10
Example
Testingtime = [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 11
Example
206_M2 12
MATLAB Windows
206_M2 13
MATLAB Windows
Current Directory Window Command Window Command History Workspace Window Document Window
Array Editor
Graphics Window Editor Window Start Button
206_M2 14
Scalar Operations
Exponentiation ^ Multiplication * Division / Addition + Subtraction -
Precedence
2
3
4
206_M2 15
Expressions
num = x^3 - 2*x^2 + x - 6.3;
den = x^2 + 0.05*x - 3.14;
f = num/den;
14.35.0
3.622
23
xx
xxxf
206_M2 16
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 17
Array Operations
Arrays with Scalars Same
Arrays with Arrays Same for Addition and Subtraction
Element-by-Element Operations Exponentiation .^ Multiplication .* Division ./
206_M2 18
Number Display
Scientific Notation LightSpeed = 2.99792e08;
Display Format format long format long e format short format short e format bank format +
206_M2 19
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 20
Problem Solving Applied
UDF Engine Performance Problem Statement
Calculate the velocity and acceleration using a script M-file
Input/Output Description
VelocityStart Time = 0 sec
AccelerationFinal Time = 120 sec
Time Increment = 10 sec
206_M2 21
Problem Solving Applied
Hand Examplevelocity = 0.00001 time3 - 0.00488 time2 +
0.75795 time + 181.3566acceleration = 3 - 0.000062 velocity2
For time = 100 sec velocity = 218.35 m/sec acceleration = 0.04404 m/sec2
Algorithm Development (outline)Define time matrixCalculate velocity and accelerationOutput results in table
206_M2 22
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 23
Testing
206_M2 24
Summary
MATLAB Environment Scalar Operations Array Operations Saving Your Work End of Chapter Summary
MATLAB Summary Characters, Commands and Functions
Key Terms