اسم المؤلف
Sulaymon Eshkabilov
التاريخ
29 نوفمبر 2022
المشاهدات
486
التقييم

Beginning MATLAB and Simulink – From Beginner to Pro
Second Edition
Sulaymon Eshkabilov
Acknowledgments xxiii
Introduction .xxv
Chapter 1: Introduction to MATLAB 1
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
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
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
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
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
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
Exercise 26 256
Exercise 27 256
Chapter 3: Graphical User Interface Model Development 257
GUIDE 257
Example 1: Building a 2D Plot 264
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
Exercise 4 320
Exercise 5 320
Chapter 5: Simulink Modeling Essentials 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
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
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
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
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
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 3: Newton’s Second Law 552
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 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
Summary 587
References 587
Self-Study Exercises 588
Exercise 1 588
Exercise 2 589
Exercise 3 589
Exercise 4 589
Exercise 5 590
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
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
Computing values of math functions
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
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
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
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
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)
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
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 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
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
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
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
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
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
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
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