+ All Categories
Home > Documents > MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

Date post: 04-Jan-2016
Category:
Upload: cynthia-bradford
View: 222 times
Download: 2 times
Share this document with a friend
24
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
Transcript
Page 1: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

MATLAB Environment

ELEC 206

Computer Applications for Electrical Engineers

Dr. Ron Hayne

Page 2: 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

Page 3: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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++)

Page 4: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 4

Problem-Solving

An Engineering Problem-Solving Methodology Problem Statement Input/Output Description Hand Example Algorithm Development Testing

Page 5: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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

Page 6: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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

Page 7: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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

Page 8: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 8

Example

Testing

Page 9: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 9

Example

Page 10: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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];

Page 11: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 11

Example

Page 12: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 12

MATLAB Windows

Page 13: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 13

MATLAB Windows

Current Directory Window Command Window Command History Workspace Window Document Window

Array Editor

Graphics Window Editor Window Start Button

Page 14: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 14

Scalar Operations

Exponentiation ^ Multiplication * Division / Addition + Subtraction -

Precedence

2

3

4

Page 15: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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

Page 16: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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);

Page 17: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 17

Array Operations

Arrays with Scalars Same

Arrays with Arrays Same for Addition and Subtraction

Element-by-Element Operations Exponentiation .^ Multiplication .* Division ./

Page 18: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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 +

Page 19: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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

Page 20: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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

Page 21: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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

Page 22: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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']

Page 23: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

206_M2 23

Testing

Page 24: MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

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


Recommended