This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Introduction to MATLAB
MATLAB Toolboxes
Computer Applications in CEE
Drs. Trani and Rakha
Civil and Environmental Engineering
Virginia Polytechnic Institute and State University Spring 2000 Virginia Polytechnic Institute and State University 1 of 31 Sample Toolboxes
• MATLAB has been extended over the years to respond to
the needs of various users • Several toolboxes exist to add to the power of the original
language. For example:
 Simulink
Fuzzy Logic
Neural Networks
Optimization
Controls
C/C++ compiler library
Realtime workshop Virginia Polytechnic Institute and State University 2 of 31 Simulink
• Simulink is a powerful toolbox to solve systems of
differential equations • Simulink has applications in Systems Theory, Control,
Economics, Transportation, etc. • The Simulink approach is to represent systems of ODE
using block diagram nomenclature • Simulink provides seamless integration with MATLAB.
In fact, Simulink can call any MATLAB function • Simulink interfaces with other MATLAB toolboxes such
as Neural Network, Fuzy Logic, and Optimization
routines Virginia Polytechnic Institute and State University 3 of 31 Simulink Building Blocks
• Simulink has a series of libraries to construct models • Libraries have object blocks that encapsulate code and
behaviors • Connectors between blocks establish causality and ﬂow
of information in the model Virginia Polytechnic Institute and State University 4 of 31 Simulink Interface
• The main application of Simulink is to model continuous
systems • Perhaps systems that can be described using ordinary
differential equations Virginia Polytechnic Institute and State University 5 of 31 Typical Simulink Libraries
Shown are some typical Simulink libraries (Macintosh) Virginia Polytechnic Institute and State University 6 of 31 Sample Simulink Library (Windows and UNIX)
The new Simulink interface in Windows/UNIX uses
standard OOP interfaces (Visual C++, Visual Basic) Virginia Polytechnic Institute and State University 7 of 31 Simulink Example
The following example illustrates the use of Simulink to
solve a two vehicle carfollowing problem. This problem
has been studied for the past 40 years in trafﬁc ﬂow
theory x˙( t + τ ) fc = k ( x ( t ) lc – x ( t ) fc )
˙
˙
˙
where: k is a gain constant of the response process x˙( t + τ ) fc is the acceleration of the following vehicle
˙
x ( t ) lc is the speed of the leading vehicle
˙
x ( t ) fc is the speed of the following vehicle
˙
Virginia Polytechnic Institute and State University 8 of 31 SetUp of the Problem
• Assume the velocity proﬁle of the leading vehicle is
known (we “drive” this car to test the response of the
following vehicle) • Initially, assume no time lags in the acceleration response
of the following vehicle ( τ = 0 ) • Test an emergency braking maneuver executed by the
ﬁrst vehicle at 3 m/s2 • Test a new scenario with a deterministic time lag
response time of 0.75 seconds • Verify that both cars do not collide Virginia Polytechnic Institute and State University 9 of 31 Simulink Representation of the CarFollowing
Problem
Car Following Problem
Mux
Speed Profiles Mux1 1 Xdot X 1 s
Integrator s
Integrator1 Mux
Mux Distance Profiles Speed LTU
2
k (Xdot_ltu  Xdot_ftu) Xdot_ltu  Xdot_ftu Constant 1
s
Integrator2 Virginia Polytechnic Institute and State University 10 of 31 CarFollowing Model Output
Velocity proﬁles for leading and trailing vehicles
Speed (m/s) Time (s) Virginia Polytechnic Institute and State University 11 of 31 CarFollowing Model Output
The time space diagram below illustrates an emergency
braking maneuver for the leading vehicle
Space (m) Time (s) Virginia Polytechnic Institute and State University 12 of 31 CarFollowing Model with Delay
A pure transport delay block is added to the original
model simulating the transport lag dynamics of a manmachine system
Mux
Speed Profiles Mux1
Xdot
X 1 1 s
Integrator s
Integrator1 Mux
Mux Distance Profiles Transport
Delay
Speed LTU
Xdot_ltu  Xdot_ftu
k (Xdot_ltu  Xdot_ftu)
1
Constant
1
s
Integrator2 Virginia Polytechnic Institute and State University 13 of 31 Output of the CarFollowing Model with Delay
• The output suggests that a collision occurs with τ
=0.75s. Space (m) Time (s)
Virginia Polytechnic Institute and State University 14 of 31 Brief on C/C++ Compiler
• Converts MATLAB MFiles to C and C++ code • Using this toolbox all graphics and math code can be
converted to develop standalone applications • Typically requires MATLAB compiler and the MATLAB
C/C++ library • New features in version 5.3 also convert cell and
structure arrays • My limited experience with this toolbox suggest
substantial gains in speed if no vector operations have
been implemented in the code • Vector operations show very little improvement when the
code is compiled
Virginia Polytechnic Institute and State University 15 of 31 Neural Network Toolbox Input
a3 P P
W1
RxQ
Z1xR
1 a1
n1 W2 Z1xQ F2
n2 Z2xZ1 , a2 W3 Z2xQ
Z3xZ2 F3
n3 Z3xQ Z1xQ F1
b1
Z1x1 1 b2 Z2xQ
Z2X1 1 b3 Z3xQ Z3x1 • Provides 100+ functions to simplify the training,
generalization and implementation of artiﬁcial neural
networks • The functional implementation of the ANN toolbox is
just through a series of MATLAB functions • All ANN functions are execued from the command line
Virginia Polytechnic Institute and State University 16 of 31 Relevant Functions Provided
• Layer initialization functions (NguyenWidrow) • Learning functions (gradients, perceptron, WidrowHoff) • Analysis functions (max. learning rate, error surface) • Line search functions (Golden section, backtraking) • Network functions (competitive, feedforward wth
backpropagation) • Performance functions (mean absolute error, SEE) • Training functions (BFGS, Bayesion regularization,
FletchelPowell, LavenbergMarquardt, etc.) • Transfer functions (log signmoid, tangent sigmoid, etc.) Virginia Polytechnic Institute and State University 17 of 31 Example of ANN Using MATLAB
Problem:
• To estimate aircraft fuel consumption based on aircraft
performance parameters • Implementation on fasttime simulation models
(SIMMOD, RAMS, etc.)
Solution • Prototype model using MATLAB’s neural Network
Toolbox • Verify the accuracy of the model with the current stateofthe art Virginia Polytechnic Institute and State University 18 of 31 Sample Data Presented in Flight Manual Virginia Polytechnic Institute and State University 19 of 31 Modeling Approach
Training Data Set Learning Module
Import Data Data Normalization Forward
Propagation Input learning pairs Compute
Error
Initialize connection
Weights Configuration
Parameters Change and
Update weights
YES Error<
eg NO
Number
of cycles > me
eg  maximum allowable error
me maximum allowable iterations NO YES
End of learning Virginia Polytechnic Institute and State University 20 of 31 Selected ANN Topology
n 1
1 sum
1
b
1
w
1,1 f1 a 1
1 w 2 1,1 n 2
1 sum f2 2
b 1
f1 sum 1 f2 sum a sum f1 sum f1 sum 1 f2 sum Target 2 f2 Altitude
Mach n sum
f1 f2 Initial
Weight sum ISA Cond. sum f1 sum sum f1 sum f2 1 Fuel burn f3 f2 1
w
8,4 sum 3 b n f1 sum
n sum 1
8 a 1
8 w 2
8,8 b a 3
1 2
8 2
8 f2 2
8 Where f1  logsigmoid transfer function
f2  tansigmoid transfer function
f3  purelin transfer function Virginia Polytechnic Institute and State University 21 of 31 ANN Data
The data sets used to develop and train the ANN are
shown below. Generalization of the ANN was conducted
using another (random) data set
Flight Phase
Takeoff and Climbout
Climb to Cruise Altitude
Cruise
Descent Number of Testing Points
Nor applicable (linear regression used instead)
850 (Fuel)
850 (Distance)
805
1210 (Fuel)
140 (Distance) Virginia Polytechnic Institute and State University 22 of 31 Summary of Results (Fokker F100)
The results shown in the table illustrate the accuracy of
the model
Flight Phase
Climb
• Distance • Mean
Error (%) Standard
Deviation (%) Null Hypothesis
(ttest at α = 0.01 ) 0.377
1.026 0.305
0.190 Accept
Accept 0.034 0.334 Accept Fuel Cruise Speciﬁc
Air Range Virginia Polytechnic Institute and State University 23 of 31 Flight Phase
Descent
• Distance • Mean
Error (%) Standard
Deviation (%) Null Hypothesis
(ttest at α = 0.01 ) 1.760
1.423 1.860
1.177 Accept
Accept Fuel Virginia Polytechnic Institute and State University 24 of 31 Sample Results (Climb Fuel)
• The results of training an ANN with 3 layers are shown
below
6000
Actual Data 5000 Climb Fuel (lb) * Estimated Data 4000
3000
2000
1000
0 0 5 10 15 20 25 30 35 40 Pressure Altitude (kft) Virginia Polytechnic Institute and State University 25 of 31 Absolute Error of ANN
The errors of the ANN are very small as depicted in this
graph for SFC
160
Complete flight envelope 140 0.60 < Mach < 0.75 Frequency 120 10,000 ft < altitude < 37,000 ft
58,000 lb < weight < 98,000 lb 100 805 data points 80
60
40
20
0
1.5 1 0.5
0
0.5
Specific Range Error (%) Virginia Polytechnic Institute and State University 1 1.5 26 of 31 Application of the Model to Complete Flight Plans
The ANN model developed has been applied to a generic
ﬂight trajectory generator with very accurate results
Constant heading
segments
Flight plan waypoints Altitude (kft) 30 Climb Descent 20
DFW 10 29.5 Pseudoglobe circle route 0
80 MIA 28
27.5 85
90 Longitude (deg) 29
28.5 27
26.5 95
100 Latitude (deg) 26 Virginia Polytechnic Institute and State University 27 of 31 Complete Flight Plan Correlation
Cruise Flight
Level (FL) Distance
(nm) /
Time (hr) Flight Manual
Fuel Burn
(lb) Neural Net
Fuel Burn (lb) Percent
Difference (%) ROAaMDWb 280 448 / 1:08 6,457 6,546 1.37 310 448 / 1:10 6,360 6,330 0.46 MIAcDFWd 310 972 / 2:24 11,851 11,865 0.12 350 972 / 2:13 11,510 11,544 0.29 290 352 / 0:57 5,298 5,260 0.71 330 352 / 0:58 5,343 5,429 1.61 290 518 / 1:20 6,990 7,047 0.80 330 518 / 1:21 7,009 7,082 1.04 Flight ROALGAe
ATLfMIA a. ROA  Roanoke Regional Airport (Virginia)
b.MDW  Midway Airport (Illinois)
c. MIA  Miami International (Florida)
d.DFW  DallasForth Worth International (Texas)
e. LGA  Laguardia Airport (New York)
f. ATL  Atlanta Hartsfield International Airport (Georgia) Virginia Polytechnic Institute and State University 28 of 31 Sample Source Code
% Initialize Weights and Biasis
nns = 8; % Number of Neurons in each layer
nns2 = 8;
%********************************
%
For Climb Distance **
%********************************
[W31_cb_d,b31_cb_d,W32_cb_d,b32_cb_d,W33_cb_d,
b33_cb_d ]=initff(P1_cbd,nns,'logsig',nns2 ...
,'tansig',T1_cbd,'purelin');
% Taining of the neural networks using LavenbergMarquardt Alogrithm Virginia Polytechnic Institute and State University 29 of 31 [W31_cb_d,b31_cb_d,W32_cb_d,b32_cb_d,W33_cb_
d,b33_cb_d ]= trainlm(W31_cb_d,b31_cb_d,'logsig' ...
,W32_cb_d,b32_cb_d,'tansig',W33_cb_d,b33_cb_d,'pure
lin',P_cbd,Ta_cbd,tp);
%********************************
%
For Climb Fuel
**
%********************************
[W31_cb_f,b31_cb_f,W32_cb_f,b32_cb_f,W33_cb_f,b3
3_cb_f ]=initff(P1_cbf,nns,'logsig',nns2,'tansig' ...
,T1_cbf,'purelin');
% Taining of the neural networks using LavenbergMarquardt Alogrithm
[W31_cb_f,b31_cb_f,W32_cb_f,b32_cb_f,W33_cb_f,b3
3_cb_f ]=
trainlm(W31_cb_f,b31_cb_f,'logsig',W32_cb_f ...
Virginia Polytechnic Institute and State University 30 of 31 ,b32_cb_f,'tansig',W33_cb_f,b33_cb_f,'purelin',P_cbf,
Ta_cbf,tp); Virginia Polytechnic Institute and State University 31 of 31 ...
View
Full
Document
This note was uploaded on 10/16/2011 for the course MECHANICAL 000 taught by Professor R during the Fall '11 term at IUPUI.
 Fall '11
 R

Click to edit the document details