Hardcore Programming for Mechanical Engineers
Total Page:16
File Type:pdf, Size:1020Kb
INDEX Symbols radius, 148 ** (dictionary unpacking), 498 class, 37 % (modulo), 134, 296 __dict__, 69 __init__, 38 P** (power), 69 (summation), 366 instantiation, 37 self, 38 A clean code, 155 coefficient matrix, 360 abstraction, 299 collections, 11–20 affine space, 172 dictionary, 18 affine transformation, 172–174 list, 15 augmented matrix, 173 set, 11 concatenation, 181 tuple, 12 identity transformation, 174, 193 collinear forces, 397 inverse, 185 color rotation, 190 #rrggbbaa, 206 scaling, 187 column vector, 340 analytic solution, 290 command animation, 288 cat, 54 frame, 288 cd, 52 architecture, software, 234 chmod, 262 attribute, class, 37 echo, 53 attribute chaining, 104 ls, 52 mkdir, 53 B pwd, 51 rm, 54 backward substitution, 364, 377 sudo, 56 balanced system of forces, 389 touch, 53 binary operator whoami, 51 intersection, 160 command line, 49 bisector, 128 absolute path, 52 bitmap image, 204 argument, See option browser option, 54 developer tools, 205 processor, 49 byte string, 213 program, 233 relative path, 52 C standard input, 58 Cholesky decomposition, numerical standard output, 58 method, 365 compound inequality, 158 circle cross product, 79 center, 148 Crout, numerical method, 363 chord, 155 D F debugger, xxxix–xliii fstrings, 89 breakpoint, xl factory function, 89 console, xliii fail fast, 109 run configuration, xli force stack frame, xlii axial, 390 Step into, xli axial component, 78 Step over, xli compression, 390, 393 decoding, 213 normal, See axial decorator shear, 391 property, 39 shear component, 83 decoupled, 308 tangent, See shear degrees of freedom, 397 tensile, 393 Demeter, law of, See principle of least tension, 390 knowledge forward substitution, 364, 375 destructuring, 20–21 fracture strain, 394 deterministic, 99 frames per second (FPS), 290 differential equation, 290 free body diagram, 288 direction vector, 103 frictionless union, 396 direction versor, 103 function docstring, 9 access modifiers, 29 documentation higherorder, 27–29 Sphinx, 10 inside function, 28 domain logic, 233 lambda, 26–27 domain of knowledge, 160 predicate, 30 Doolittle, numerical method, 363 pure, 24–25 dot product, 77 reducer, 32 dunder methods, See magic methods shared state, 25 duplication of code, See knowledge side effect, 25 duplication functional programming, 23–36 dynamic dispatching, 42 functools reduce, 32–35 E edge case, 143 G eigenvalues, 362 geometry environment variable, 262 t parameter, 107 PWD, 262 circle, 148–149 PYTHONPATH, 262 line, 124 errors parallelogram, 164 AttributeError, 41 point, 67–71 EOFError, 317 polygon, 132–133 IndexError, 15, 341 rectangle, 155–157 ValueError, 133 segment, 101 ZeroDivisionError, 143 vector, 71–85 Euler’s numerical method, 290 versor, 75, 90 event driven, 267 Git, xxix event handler, 267 GitHub, xxix exception global userdefined, 111 dict, 18 550 Index enumerate, 14, 16 linear equation, 359 filter, 30–31 coefficients, 360 help, 10 free term, 360 len, 11, 13, 15 unknown, 360 list, 15 linear interpolation, 193 map, 31–32 linear transformation, 172 range, 146 Linux set, 11 distro, 50 str, 88 superuser, 56 tuple, 13 list append, 16 H flatten, 280 slice, 16–17 hardcoding, 248 list comprehension, 35–36 Hooke’s law, 392 LU factorization, 362 I M IDE, See integrated development magic methods, 43 environment __add__, 44, 70 immutability, 23, 25–26 __eq__, 45, 86 immutable, 12, 219 __str__, 88 import __sub__, 44, 70 alias, 8, 430 magic numbers, 110, 430 relative, 9, 240 __main__, 4 __init__.py, 4 main loop, See time loop InkStructure, application, 188 markdown, xxx integrated development environment, matrix, 337 xxxi identity, 184 integration test, 381, 447 lowertriangular, 362 internal forces, 389 main diagonal, 361 interpolation, 192 nonsingular, 363 easeinout, 194 positive definite, 362 iterator, 30 square, 346, 361 symmetric, 361 J transposed, 349 JSON format, 248 uppertriangular, 362 mechanical stress, 390 K model space, 184 modular arithmetic, 135 keyword module, 4 class, 37 argparse, 531 def, 24 add_argument, 533 lambda, 26 ArgumentParser, 532 None, 120 import, 5–9 knowledge duplication, 160 json, 249 loads, 249, 496 L math, 66 lambda calculus, 26 copysign, 82 fabs, 66 Index 551 operator, 34 % (modulo), 134, 296 os ** (power), 69 getcwd, 261 in, 11, 14, 19 os.path overloading, 43, 70 normpath, 261 ternary, 349 sys out of bounds, See errors: IndexError path, 259 Tkinter, 266 P unittest, 92 package, 4 assertAlmostEqual, 92 parser, 468 assertEqual, 95 parsing, 483 assertFalse, 97 pascal case, 37 assertIsNone, 121 pass, 293 assertRaises, 112 PEP 238, 240 assertTrue, 97 plaintext file, 235 TestCase, 92 plane truss, 394 moment point bending, 392 projections, 67 normal to section, 391 polygon tangent to section, 391 centroid, 137 torsional, 391 perimeter, 133 multiple assignment, 120 side, 132, 133 mutable, 219 vertex, 132 polygonal chain, 132 N principle of least knowledge, 125 __name__, 4 proportional limit, 394 Newton’s third law, 423 Python Enhancement Proposal, See nonlinear equation, 360 PEP normal (perpendicular) versor, 104 Python Standard Library, xxvi number floating point, See real R real, 65 raise exception, 111 numerical method, 359, 361 raster image, See bitmap image direct, 361 raw string literal, 245 iterative, 361 ray casting algorithm, 139 reaction force, 412 O readme, xxix object, 36 rectangle encapsulation, 346 origin, 155 method, 40–43 overlap, 158 signature, 43 size, 155 property, 39–40 refactoring code, 301 state, 277 regex, See regular expression objectoriented programming, 36–45 regression, 91 open interval, 160 regular expression, 241–246 open source, 98 capture group, 245 operator character set, 242 ** (dictionary unpacking), 498 quantifier, 243 552 Index resistant element, 388 rect, 219 reusability, 308 text, 224 richtext editor, 205, 235 transform, 208 rotation viewBox, 207 pivot, 189 system of equations row vector, 340 matrix form, 337, 360 run configuration, xxxvi, 236 T S TDD, See TestDriven Development Scalable Vector Graphics, See SVG template, 210 scientific notation, number, 526 placeholder, 210 screen space, 184 test script, 4 assertion, 91 segment fixture, 98 direction, 103 subject, 91, 98 set test double, 447 add, 12 dummy, 447 difference, 12 fake, 447 remove, 12 mock, 448 union, 12 stub, 448 side effect, 24 testdriven development, 371 silent fail, 109 time loop, 291 simulation, 289 Tkinter ahead of time, 290 Button, 269 motion, 297 Canvas, 270 real time, 290 Entry, 268 system, 288 Label, 268 time delta, 291 main loop, 267 static equilibrium, 389, 417 widget, 266 stiffness, 397 traceback, 94 stiffness matrix, 398 truss structure, 388 strain ϵ, 393 tuple stress σ, 393 count, 13 stressstrain diagrams, 393 index, 14 string, 211 type hints, 45–46 join, 214 float, 46 structure, 388 int, 46 external constraint, 395 str, 46 external support, See external constraint U node, 395 ultimate strength, See ultimate stress twoforce member, 397 ultimate stress, 394 SVG, 204 Unicode characters, 525–526 attributes, 206, 215 unit testing, 90–91 circle, 221 three golden rules, 97–99 group, 225 Controlled Environment, 98 line, 217 One Reason to Fail, 98 polygon, 222 Test Independence, 99 polyline, 223 Index 553 Unix W prompt, See terminal winding number algorithm, 140 shell, See terminal Windows Subsystem for Linux, 50 terminal, 50 working directory, 259 unpacking, See destructuring World Wide Web Consortium (W3C), UTF8 encoding, 213 204 utils package, 134 wrapper class, 276 V X vector XML, 205 angle, 81 namespace, 205 norm, 74 normal, 75 Y normalize, 75 parallelism, 81 yield strength, See yield stress perpendicularity, 81 yield stress, 394 unit, 75 yielding, material, 394 vector image, 204 Young’s modulus, 392 version control system, xxix visibility diagram, 308 554 Index.