Beginning MATLAB and Simulink – From Beginner to Pro
Beginning MATLAB and Simulink – From Beginner to Pro
Second Edition
Sulaymon Eshkabilov
Table of Contents
About the Author .xix
About the Technical Reviewers xxi
Acknowledgments xxiii
Introduction .xxv
Chapter 1: Introduction to MATLAB 1
Menu Panel and Help 2
The MATLAB Environment 8
Working in the Command Window 9
Command Window and Variables 11
Using Variables 11
When to Use the Command Window 19
Different Variables and Data Sets in MATLAB 24
Numerical Data/Arrays 26
Not a Number 34
Character Type of Variables 40
Function Handle 42
Logical Arrays 47
Table Arrays 50
Cell Arrays 54
Structure Arrays 60
Complex Numbers 65
Precision 65
M-fiie and MLX-fiie Editors 66
M-file Editor 67
MLX-file Editor 69
VTABLE OF CONTENTS
% Comments 71
Closing the MATLAB Window 79
Summary 79
References 79
Exercises for Self-Testing 80
Exercise 1 80
Exercise 2 80
Exercises 81
Exercise 4 81
Exercises 81
Exercise 6 81
Exercise 7 81
Exercises 81
Exercise 9 82
Exercise 10 82
Exercise 11 83
Exercise 12 83
Exercise 13 83
Exercise 14 83
Exercise 15 84
Exercise 16 84
Exercise 17 85
Exercise 18 85
Exercise 19 85
Exercise 20 85
Exercise 21 85
Exercise 22 86
Exercise 23 86
Exercise 24 87
Exercise 25 87
Exercise 26 87
viTABLE OF CONTENTS
Exercise 27 87
Exercise 28 88
Exercise 29 88
Exercise 30 88
Exercise 31 88
Exercise 32 89
Exercise 33 90
Exercise 34 90
Exercise 35 91
Exercise 36 91
Exercise 37 92
Exercise 38 92
Exercise 39 92
Exercise 40 93
Exercise 41 93
Exercise 42 95
Exercise 43 96
Exercise 44 97
Exercise 45 97
Chapter 2: Programming Essentials 99
Writing M/MLX-Files 99
How to Create an M/MLX-File 102
Warnings in Scripts 102
Errors in Scripts 108
Cell Mode 122
Debugging Mode 126
M-Lint Code Check 127
Code Profiling 128
Dependency Report 130
P-Codes 131
Some Remarks on Scripts/M/MLX-Files 132
viiTABLE OF CONTENTS
Display and Print Operators: display, sprintf, and fprintf 133
Example 1 133
Example 2 134
fprintf( ) 135
Control Statements: [if, else, elseif, end], [switch, case, end] 142
Example 1 144
Example 2 145
Example 3 147
Example 4 152
Loop Control Statements: while, for, continue, break, end 153
Example 1 154
Example 2 155
Example 3 159
Example 4 161
Example 5 162
Example 6 164
Example 7 168
Example 8 171
Example 9 172
Example 10 173
Example 11 174
Memory Allocation 175
Example 12 176
Example 13 178
Example 14 179
Example 15 182
Example 16 183
Example 17 188
Example 18 191
Example 19 192
viiiTABLE OF CONTENTS
Symbol References in Programming 194
Asterisk 195
At Sign 195
Colon 196
Comma 196
Curly Brackets 196
Dollar Sign 197
Dot 197
Dot-Dot 197
Dot-Dot-Dot (Ellipsis) 197
Parentheses 198
Percent 198
Semicolon 199
Single Quotes 199
Slash and Backslash 200
Square Brackets 200
Function Files 201
Example 1 203
Example 2 205
Example 3 206
Example 4 207
Most Common Errors with the Function Files 210
Varying Number of Inputs and Outputs 212
Nested and Subfunctions of Function Files 228
Function Files Within M-Files 231
Summary of Scripts and Function Files 233
Inline Functions 234
Example 1 235
Example 2 235
Example 3 235
ixTABLE OF CONTENTS
Anonymous Functions with Handles 236
Example 1 236
Example 2 237
Example 3 237
Summary 238
Exercises for Self-Testing 239
Exercise 1 239
Exercise 2 239
Exercise 3 240
Exercise 4 240
Exercise 5 241
Exercise 6 242
Exercise 7 242
Exercise 8 243
Exercise 9 244
Exercise 10 245
Exercise 11 246
Exercise 12 247
Exercise 13 249
Exercise 14 250
Exercise 15 250
Exercise 16 250
Exercise 17 251
Exercise 18 251
Exercise 19 252
Exercise 20 252
Exercise 21 253
Exercise 22 253
Exercise 23 254
Exercise 24 255
Exercise 25 255
xTABLE OF CONTENTS
Exercise 26 256
Exercise 27 256
Chapter 3: Graphical User Interface Model Development 257
GUIDE 257
Example 1: Building a 2D Plot 264
Example 2: Adding Functionality 271
Example 3: Solving a Quadratic Equation 275
Editing the Callback Functions 279
GUI Dialogs and Message Boxes 283
Error Dialog 284
Warning Message 284
F1 Help/Message Box 285
General Syntax 286
Input Dialog 287
Question Dialog 288
Summary 295
Exercises for Self-Testing 295
Exercise 1 295
Exercise 2 296
Exercise 3 297
Chapter 4: MEX Files, C/C++, and Stand-Alone Applications 299
Verifying Compilers 300
Generating C Code 300
Creating MEX Files from Other Languages 312
Building Stand-Alone Applications 313
Summary 318
Exercises for Self-Testing 319
Exercise 1 319
Exercise 2 319
Exercise 3 319
xiTABLE OF CONTENTS
Exercise 4 320
Exercise 5 320
Chapter 5: Simulink Modeling Essentials 321
Simulink Modeling 321
Example: Arithmetic Calculations 323
Example: Modeling Simple Arithmetic Operations 328
Performing Matrix Operations 332
Computing Values of Functions 337
Input/Output Signals from/to the MATLAB Workspace 345
Simulating a Mechanical System 349
Working with a Second-Order Differential Equation 357
Subsystem in Simulink Modeling 362
Simulink Model Analysis and Diagnostics 368
Summary 376
Exercises for Self-Testing 376
Chapter 6: Plots and Data Visualization 379
Basics of Plot Building 379
PLOT() 380
Example 1: Plotting Two Rows of Data 380
Example 2: Plotting Function Values 381
Example 3: Building a Histogram 383
Example 4: Building a Bar Chart 383
Example 5: Building a 3D Pie Chart 384
TITLE, XLABEL, YLABEL, AXIS, GRID, and LEGEND 385
TITLE() 385
Example 6: Plotting a Unit Circle with Plot Tools 386
LINE and MARKER Specifiers 387
Example 7: Plotting Sine Function Values with Plot Tools 390
Example 8: Plotting Sine Function Values with Plot Tools 392
xiiTABLE OF CONTENTS
Plot Two Data Sets in Two Y-Y Axes 393
Example 9: Plotting Two Function Values on Y-Y Axes 393
Subplots 396
Example 10: Building Subplots of Functions 396
LEGEND 397
HOLD 398
Example 11: Plotting a Few Function Values in One Plot 398
Example 12: Plotting Function Values with Different Line Markers and Colors 399
Example 13: Bar Chart of Data with Standard Deviation 402
Example 14: Bar Chart of Data with Values Shown 403
Example 15: Bar Chart of Data with NaN Values Shown and Axis Tick Labels Off 404
EZPLOT, FPLOT, and FIMPLICIT with Function Handles (@) 406
Example 16: Plotting a Mathematical Expression with ezplot() 407
GTEXT, TEXT, and GINPUT 408
Example 17: Locate and Display Minimum Values of a Function Plot in a Plot Figure 409
Axis Ticks and Tick Labels 410
Example 18: Display X-Axis Tick Labels 410
Figure Handles 412
Example 19: Working with Figure Handles 412
3D Surface Plots 414
Example 20: Creating a 3D Pie Plot with pie() 414
Example 21: Creating a 3D Surface Plot with ezsurff) 415
Example 22: Creating a 3D Mesh Plot with ezmeshf) 416
Example 23: Creating a 3D Surface-Contour Plot with ezsurfcf), fsurf(), and surfc() 417
Example 24: Creating a 3D Plot of an Electric Potential Field 419
Example 25: Creating 3D Plots with waterfall(), ribbonf), meshc(), contour() 421
Save Plot Figure with saveas() 424
3D Line Plots and Animations 426
Example 26: Building 3D Line Plots and Animated 3D Line Plots with plot3(),
comet3(), and ezplot3() 426
xiiiTABLE OF CONTENTS
Animated Plots 428
Example 27: Building an Animated Plot with getframe() 428
Example 28: Building an Animated Plot with drawnow 428
Example 29: Building an Animated Plot with drawnow 429
Example 30: Building an Animated Plot of a Projectile with getframe() 429
Summary 430
Exercises for Self-Testing 432
Exercise 1 432
Exercise 2 432
Exercise 3 432
Exercise 4 433
Exercise 5 434
Exercise 6 434
Exercise 7 435
Exercise 8 435
Exercise 9 436
Exercise 10 436
Exercise 11 436
Exercise 12 436
Exercise 13 437
Exercise 14 437
Exercise 15 437
Exercise 16 438
Exercise 17 438
Exercise 18 438
Exercise 19 439
Exercise 20 439
Exercise 21 440
Exercise 22 440
Exercise 23 441
Exercise 24 441
Exercise 25 441
xivTABLE OF CONTENTS
Chapter 7: Linear Algebra 443
Introduction to Linear Algebra 443
Matrix Properties and Operators 444
Simulink Blocks for Matrix Determinant, Diagonal Extraction, and Transpose 446
Matrix Inverse or Inverse Matrix 450
Simulink Blocks for Inverse Matrix 451
Matrix Operations 482
Example: Performing Matrix Operations 485
Standard Matrix Generators 493
Vector Spaces 499
Polynomials Represented by Vectors 501
Simulink Model-Based Solution of Polynomials 503
Eigen-Values and Eigen-Vectors 504
Matrix Decomposition 507
QR Decomposition 508
LU Decomposition 511
Cholesky Decomposition 515
Schur Decomposition 519
Singular Value Decomposition 521
Logic Operators, Indexes, and Conversions 524
Logical Indexing 525
Example: Logical Indexing to Locate and Substitute Elements of [A] Matrix 528
Conversions 530
Example: Creating Character Strings with char() 532
Summary 535
References 536
Exercises for Self-Testing 536
Exercise 1 536
Exercise 2 537
Exercise 3 538
Exercise 4 538
XVTABLE OF CONTENTS
Exercise 5 539
Exercise 6 539
Exercise 7 540
Exercise 8 540
Exercise 9 540
Exercise 10 541
Exercise 11 541
Exercise 12 542
Exercise 13 542
Exercise 14 542
Exercise 15 543
Exercise 16 543
Exercise 17 544
Exercise 18 544
Exercise 19 545
Exercise 20 545
Exercise 21 545
Exercise 22 545
Exercise 23 546
Exercise 24 546
Exercise 25 546
Exercise 26 546
Exercise 27 547
Exercise 28 547
Exercise 29 547
Exercise 30 548
Chapter 8: Ordinary Differential Equations 549
Classifying ODEs 550
Example 1: Unconstrained Growth of Biological Organisms 551
Example 2: Radioactive Decay 551
Example 3: Newton’s Second Law 552
xviTABLE OF CONTENTS
Analytical Methods 553
DSOLVE 553
Example 1: Using DSOLVE 554
Example 2: Plotting the Found Solution with dsolve 554
Example 3: Adding an Unspecified Parameter 555
Second-Order DDEs and a System of DDEs 556
Example 1: dsolve with a Second-Order ODE 557
Example 2: System ODEs 557
Example 3: Unsolvable Solutions Using dsolve 558
Example 4: Computing an Analytical Solution 559
Example 5: An Interesting ODE 560
Laplace Transforms 560
Example 1:First Laplace Transform 562
LAPLACE/ILAPLACE 563
Example 2: Using LAPLACE 564
Example 3: A Final LAPLACE 564
Example 4: Comparing LAPLACE/ILAPLACE with DSOLVE 564
Example 5: Convergent Answers 567
Example 6: No Analytical Solution 569
Example 7: Demonstrating Efficiency and Effortlessness 570
Example 8: Demonstrating MATLAB Built-in ODEx Solvers 575
Example 9: MATLAB Built-in ODEx Solvers for Second-Order ODEs 578
Example 10: Simulink Modeling 580
Summary 587
References 587
Self-Study Exercises 588
Exercise 1 588
Exercise 2 589
Exercise 3 589
Exercise 4 589
Exercise 5 590
xviiTABLE OF CONTENTS
Exercise 6 590
Exercise 7 591
Exercise 8 592
Exercise 9 592
Exercise 10 593
Index
Index
A
Acceleration equation, 114
Acell cell array, 58
Additional plot-related commands, 431
addpath(), 10, 367
Analytical methods, ODEs
dsolve, 553, 554
plotted with fplot, 554
unspecified parameter, 555
Animated plot commands, 431
Animated plots
with drawnow function, 428, 429
with getframe(), 428, 429
Anonymous function, 236, 237
App Designer, 258–261, 275
Archimedes, 255
ASCII/ANSI character symbols, 40
Astr and Bstr structure arrays, 64
axis command, 385
Axis labels, 72, 196–197, 385, 391, 392, 411
B
Blank Model, 322, 324
Blank Model window, 325, 327, 349, 359
Boolean logical arrays, 47
Boundary value problems (BVPs), 550
C
Callback functions, 257, 258,
268–272, 279–283
C/C++
MATLAB, 300
MEX files, 312
M-file, 302
source code type selection
generation, 304
Cell arrays, 54, 55, 57, 58, 60, 65, 88, 196
Characteristic polynomial, 505, 506
Cholesky decomposition, 456,
515–519, 549
Code generation, 60, 201, 300, 303, 358,
369, 371
colon (:) operator, 30, 34
Color specifiers, 389
Command History window, 18
Command window, 3, 4, 6, 7, 13, 14,
19, 24, 321
% Comments, 71, 72, 75
Computing values of math functions
adjustments to the model, 340
blocks, 338
Configuration properties of Scope,
341, 342
Ex3_Function_Compute_Simple.
slx, 345
Ex3_Function_Compute.slx, 338
fixed-step size, 339
input/output signals
from/to the MATLAB
workspace, 345–348
modeling process, 338
Scope block, 342
INDEX597
fprintf() command
formatting specifiers, 136
results, 136
sine function values, 135
syntax, 135
time and date, 136
Function files
advantages, 212
comments, 201
creation, 202
errors, 210, 212
Ex7Var.m
[for … end] loop, 222
indexing operations, 222
input arguments, 220–222
output variables, 221, 222
nargin function, 222
nargoutchk function, 223
outputs, 219, 220
output variables, 220
Ex8Var.m
four input and nine output, 226, 227
no input and nine output, 224, 227
no input and no output, 223
one input and four output, 223
one input and ten output, 227, 228
three input and no output, 224, 225
three input and three output,
225, 226
Ex23.m, 254
Ex25.m, 255
Ex26.m, 256
getREADY.m function, 206
hints, 233, 234
MATLAB, 201, 202
matlabFunction, 205, 206
M-files, 231–233
mistakes, 202
myfunction.m, 203, 205
naming, 201
nested/subfunctions, 228–230
QUAD.m, 207–209
Symbolic Math Toolbox, 205
symbols, 201
syntax/structure, 201
uses, 201
varying inputs and outputs
combinations, 212
Command window, 212
[for … end] and [while … end]
loops, 215, 216
execution, 217
iterations/error tolerance, 216
Leibnitz series, 215
Quad_Var.m, 213–215
warning and error messages, 233
Function handle, 42–47
function_pulse.m function file,
357–359, 362
Fun_File.m, 575
G
Gaussian elimination method, 457, 511
getframe, 428
GINPUT function, 410
Gram-Schmidt method, 508
Graphical user interface (GUI), 1, 99,
257, 276–278
Greek letters, 391
grid on command, 386
gtext commands, 409
GTEXT commands, 408
GUI development environment (GUIDE)
add functionality, 271–275
App Designer, 258–260
INDEX598
basic steps, 263, 264
Blank App Designer window, 261
building a 2D plot, 264–271
callbacks/callback
functions, 257
edit callback functions, 279–283
figure function, 257
GUI components with name tags
display, 261, 262
GUI controls, 258
GUI figure window components
without names, 260
GUI window, 262, 263
MATLAB GUI components, 257
modified buttons and
components, 267
Quick Start window, 258, 259
SINC function plot GUI creation, 268
sinc(πx) and quit options, 273
sinc(πx) function, 271
solving quadratic
equation, 275–278
templates, 258
GUI dialogs and message boxes
error dialog, 284
F1 help/message box, 285
general syntax, 286, 287
input dialog, 287
MATLAB, 283
question dialog
inputs, 293, 294
making choice, 288–293
warning message, 284
GUI quick access tools, 9
GUI tools, 414
H
HELLO_mex.mexw64, 313
Help library, 7
Homogeneous ODEs, 557
I, J, K
ilaplace() function, 563
In1, 344
Initial value problems (IVPs), 550, 551,
553, 574, 580, 587–589, 591, 592
Inline functions, 234, 235
Interpreted MATLAB Fcn
block, 358–362
Inverse matrix, 450, 451
Inverse matrix, Simulink blocks
DSP System, 451
efficiency of solver functions, linear
equations, 468–470
General Inverse (LU), 451
inv(A), 451
linear equations ([A]{x} = [b])
least squares method, 474–481
simulink modeling, least squares
method, 481, 482
value changes of [b], 471, 473
MATLAB functions
computing matrix
determinants, 463–465
solve linear
equations, 463–465
Pseudoinverse (SVD), 451
rank, 453
solver functions accuracy, linear
equations, 465, 467, 468
solving system, linear
equations, 454–463
GUI development environment
(GUIDE) (cont.)
INDEX599
L
LAPLACE/ILAPLACE
convergent answers, 567, 568
demonstrating efficiency and
effortlessness, 571, 573
with dsolve, 564, 566
ilaplace() function, 564
Laplace and inverse Laplace
transforms, 563
MATLAB built-in ODEx
solvers, 573–578
no analytical solution, 569, 570
second-order ODEs, MATLAB built-in
ODEx solvers, 578–580
Simulink modeling, 580, 582–584,
586, 587
Laplace transforms, 593
first, 562, 563
linear ordinary differential equations
with constant coefficients,
560, 561
schematic view, 561, 562
Least squares method, 474–481
legend command, 397
Line and marker specifiers, 387
Linear algebra
mathematics, 443
m-linear equations, 443
overdetermined, 444
underdetermined, 443
Linear equations
efficiency of solver functions, 468–470
solver functions accuracy, 465,
467, 468
Line Style Specifiers, 388
Logarithmic space, 499
Logical arrays, 47–49
Logical indexing
conversions, 530, 531
create character strings with
char( ), 532–535
functions/commands, 527
locate and substitute elements, [A]
matrix, 528–530
logic operators, 525
Loop control statements
algorithm, 154
[for … end]
approaches, 168, 170
[break] command, 188
computation algorithm, 160
EXP_Calcs.m, 184, 185
Fibonacci numbers, 188–190
F_Series.m, 182, 183
Fun_Sets.m, 193, 194
[if … else … end], 160
iteration processes, 166–168
Leibnitz series, 176–178
memory allocation, 186
mistakes, 169
outputs, 161
plot() command, 186
Pseudo_Randi.m, 178
results, 185, 188
Series_e.m, 174, 175
Series_PI.m, 173
sine function, 191, 192
Sine_Series.m, 180
solutions, 160
SqCube10.m, 161, 162
SqCubeN.m, 163, 164
Sum20odd.m, 159
SumPi6.m, 172, 174
SumSeries.m, 164, 165, 240, 241, 243
syntax, 159
INDEX600
[tic … toc] operators, 187
[timeit] operator, 188
vectorization, 171
vs. [while … end], 161
Leibnitz series, 176
memory allocation, 175
types, 153
vectorization approach, 181
wheat and chessboard problem, 171
[while…end]
approaches, 168, 170
[break] command, 188
EXP_Calcs.m, 184, 185
Fibonacci numbers, 188–190
F_Series.m, 182, 183
[if … elseif … else …end], 155
iteration processes, 166–168
Leibnitz series, 176–178
memory allocation, 186
mistakes, 169
plot() command, 186
Pseudo_Randi.m, 179
Quad_Eqn.m, 155, 157
quadratic equation, 155
results, 185
robustness, 158
Series_e.m, 174, 175
Series_PI.m, 173, 174
Sine_Series.m, 180
Sum100.m, 154
summation variable, 154, 155
SumPi6.m, 172
SumSeries.m, 164, 240, 241, 243
syntax, 153
vectorization, 171
LU decomposition
3-by-3 pascal matrix, 512, 513
Gauss elimination method, 511
built-in function lu(), 511
solve [A]{x} = [b] system, LU
composition, 514
M
MATHWORKS website, 5
MATLAB, 318, 321, 460, 493
wildcard asterisk (), 15 built-in function tools and commands, 5 C/C++ code generation, 300 C code, 299 C code generation, 301–312 C-generated code, 306 in the Command window, 9, 10 command window and variables, 11 common commands for housekeeping, 14 components, package’s GUI tools, 2 data storage format types, 16 data storage types and formats, 17, 18 default main window, 2 define input type box, 302, 303 exiting/quitting MATLAB, 79 functions, 535 GUI tools, 2 hardware board type selection options, 305 Leibnitz.m, 310 Logical Expressions, 524 MEX files, 300, 309, 310, 312, 313 ODEx numerical solvers, 587 operators, 524 precision, 65, 66, 75 programming languages, 299 Loop control statements (cont.) INDEX601 source code type selection generation, C/C++, 304 stand-alone applications, 313, 314, 316–318 strengths, 1 supported data storage types, 66 use the Command window, 19 variable names, 11, 12 variables and data sets (see Variables and data sets in MATLAB) MATLAB application, 10 on Windows operating system, 2 MATLAB built-in ODE solvers, 591, 592 MATLAB built-in ODEx solvers, 573–576, 578, 580, 588–590, 592 MATLAB Coder, 301 MATLAB-compatible files, 21 MATLAB environment, 8 changes in the layout, 8 Desktop window, 8 MATLAB files, 22 MATLAB main menu, 3 MATLAB supports wildcards, 23 Matrix Concatenate block, 492, 493 Matrix decompositions Cholesky, 515–519 conversions, 524 engineering problem solving, 507 indexes, 524 linear algebra, 507 logic operators, 524 LU, 511–515 QR, 508 Schur, 519, 521 SVD, 521, 522 types, 507 Matrix generation functions, 497 Matrix inverse, 450–454, 537 Matrix operations, 332–337 array, 483 math function block, 492 Matrix Concatenate block, 492, 493 matrix exponential and square operation blocks, 492 matrix multiplication, Simulink, 491 matrix sum and subtraction operations, Simulink, 490 performing, 485–487, 489, 490 Simulink Library, 490 two equivalent formulations, 483 Matrix properties and operators determinant, 444 diagonal, 445 inverse matrix, 450, 451 Simulink blocks (see Simulink blocks) transpose, 445 Mechanical spring-mass-damper system, 349 MEX files, 299–301, 303, 306–313, 318 M-file editor, 67, 68 M-files, 66, 299–302, 306, 308–310, 314, 315 MLX-file editor, 69–71 MLX-file editor’s main tools menu, 69 MLX file editor window, 66 MLX-files, 66 M/MLX-files algorithm, 101 cell mode, 122, 123, 125 code profiling, 128–130 code/program writing, 100 creation, 102 debugging, 101, 126 dependency report, 130, 131 differences, 113 execution, 114 extension, 99 INDEX602 features, 114 hits, 233, 234 M-Lint code check, 127, 128 P-codes, 131, 132 remarks, 132, 133 scripts (see Scripts) steps, 101 tools, 99, 100 warnings display of outputs, 103, 106 and error messages, 233 memory allocation, 103, 106 missing arguments, 105, 107 premature ending, 103, 106 unnecessary brackets, 105, 107 unnecessary semicolons, 104, 106 unrecommended function, 105, 107 uses, 102 variable names, 104 wavy lines, 102, 103 Model Advisor tools, 369–375 Model Explorer tools, 369 movie, 428 MyAppinstaller_web.exe, 316 My_fun.m, 319 N Newton’s Second Law, 552, 553 Not-a-number (NaN), 34–38 O Ordinary differential equations (ODEs), 550 classifications BVPs, 550 IVPs, 550 Newton’s Second Law, 552, 553 radioactive decay, 551 unconstrained growth, biological organism, 551 definitions, 549 Newton’s Second Law of Motion, 549 Orthogonal-triangular decomposition, 508 Out1, 344, 345 P P2.mlx, 76–78 Partial differential equations (PDEs), 549 Plot building building a bar chart, 383 building a histogram, 383 3D pie chart, 384 plot() command, 380 PLOTS tab of the main menu, 379 plotting function values, 381, 382 plotting two rows of data, 380, 381 unit circle with plot tools, 386, 387 Plot_EX26.m, 427 plot and plot3 functions, 390 Plot figure properties, 412 Plotting common errors, 431 Plotting two function values on Y-Y axes, 393–395 Polynomials Simulink model-based solution, 503, 504 vectors, 501, 503 PUBLISH tools, 68, 72 Q QR decomposition, 508 QUAD_eqn_SIM.m, 314 Quadratic equation, 108 M/MLX-files (cont.) INDEX603 R Radioactive decay, 551 randi(), 383 randn(), 383 Random number generators, 28 Resistor-inductance-capacitor (RLC) circuit, 252, 590 Right mouse button (RMB), 381 Runge-Kutta methods, 553 S saveas() function, 424, 425 Say_HELLO.c, 319 Schur decomposition, 519, 521 Scripts date and time, 250 errors, 111, 243–249 approaches, 112 commands, 108 Command window, 120 computing steps, 108 execution, 109 expressions, 116, 117 functions, 112 input argument, 113 input entries, 108 input prompts, 111 issues, 109 missing parenthesis, 111 mistyped name, 115 orange wavy line, 109 outcomes, 121 plot() command, 114 quadratic equation, 108 red waves, 108, 113 results, 112 solution, 115 values, 110 warning message, 109 workspace, 110, 112 ET1.mlx, 117 solution, 119, 250 version, 118 volume/weight of the model, 250 Second-order nonhomogeneous differential equation, 562 Second-order nonhomogeneous ODEs, 572, 589, 590, 593 Second-order ODEs, 578–580 analytical solution, 559, 560 dsolve, 557 homogeneous, 557 IVPs, 588 methods, 588 system ODEs, 557 unsolvable solutions, dsolve, 558 Series resistor-capacitor (RC) circuit, 251 Simple arithmetic operations, 328–331 Simulation processes, 238, 239 Simulink, 321 Simulink blocks, 448 diagonal extraction, 446–450 inverse matrix (see Inverse matrix, Simulink blocks) matrix determinant, 446–450 matrix inverse, 451–454 transpose, 446–450 Simulink Library, 325, 326 block sets, 328 connecting blocks, 327 Create Annotation search box, 326 dragging and dropping a block, 326 versions, 325 Simulink Library browser, 322 Simulink Library window, 325 INDEX604 Simulink Model Analysis and Diagnostics tools, 368 code generation, 369 Model Advisor tools, 369–375 Simulink modeling, 448, 450, 460–463, 481, 482, 580, 582–584, 586, 587 arithmetic calculations, 323, 324 Command window, 321 computing values of functions (see Computing values of math functions) essential graphical programming tools, 376 matrix operations, 332–337 simple arithmetic operations, 328–331 startup window, 321–323 Simulink model window, 327 Simulink startup window, 321–323 SINCfun_export.m, 275 SINCfun.fig, 275 SINCfun.m, 320 Sine function values with plot tools, 390, 392 Single-step methods, 553 Singular value decomposition (SVD), 521, 522 Skydiver, 252, 253 Special characters, 391 Specifiers, 387 sprintf () command vs. fprintf(), 136 numerical data, 137 solution script, 136, 137 syntax, 136 Stand-alone applications, 313, 314, 316–318, 320 Standard matrix generators, 493–499 Structure arrays, 60–65 Student grades, 240 Subplots Command window, 397 functions, 396 hold on command, 398 bar chart of data with NaN values, 404, 405 bar chart of data with standard deviation, 402, 403 bar chart of data with values shown, 403, 404 function values in one plot, 398, 399 plotting function values with different line markers and colors, 399–401 legend command, 397 solution script, 396 subplot() command, 396 SUModd.m function, 301, 308 SUModd_mex.c, 307 SUModd.m M-file function, 301 Symbolic Math Toolbox function, 459, 553 Symbol references at sign (@), 195 asterisk (), 195
colon (:), 196
comma (,), 196
curly brackets { }, 196
dollar sign ($), 197
dot (.), 197
dot dot ( ), 197
three dots (…), 197
single quotes (‘ ’), 199
square brackets ([ ]), 200
parentheses (), 198
percent (%), 198
INDEX605
semicolon (;), 199
slash/backslash (/ ), 200
T
3D parametric curve plotter tools, 427
3D pie chart, 384
3D plot commands, 431
3D space line plot tools, 426
3D surface plots, 414
the ezsurf() command, 415
pie chart, 414
3D mesh plot with ezmesh(), 416
3D surface-contour plot with ezsurfc(),
fsurf() and surfc(), 417–419
with waterfall(), ribbon(), meshc(),
contour(), 421, 422, 424
Table arrays, 50–54
TEXT commands, 69, 408, 409
Third-order polynomial, 256
title() command, 385
Truck speed, 253
2D plot commands, 430
2D plot properties, 414
U
Umbilic torus function, 296
umbilic_torus.m, 319
untitled.slx, 324
V
Vandermonde matrix, 476, 478, 479
Variables and data sets in MATLAB
cell arrays, 54, 55, 57, 58
character type of variables, 40–42
complex numbers, 65
data types, 24, 25
function handle, 42–47
logical arrays, 47–49
NaN values, 34–38
numerical data/arrays, 26–30, 32, 33
precision, 65, 66
structure arrays, 60–65
table arrays, 50–54
Vector spaces, 499
eigen-values, 504
eigen-vectors, 504
linspace() command, 500
logarithmic space, 499
logspace(), 500
polynomials, 501, 503
Simulink model-based solution,
polynomials, 503, 504
Vertical (y-y) axes, 393
Via the Model Explorer tools, 368
VIEW tools, 68
W
Wave equation, 251
Workspace pane, 3
Workspace window, 20
X
X-axis tick labels, 410, 411
xlabel, 385
Y
ylabel, 385
Z
zlabel, 385
كلمة سر فك الضغط : books-world.net
The Unzip Password : books-world.net
تعليقات