Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Software Solutions for Engineers and Scientists
PREMIUM
Số trang
946
Kích thước
4.9 MB
Định dạng
PDF
Lượt xem
1578

Software Solutions for Engineers and Scientists

Nội dung xem thử

Mô tả chi tiết

Software

Solutions

for

Engineers

and

Scientists

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

43021_FM.indd 1 9/10/07 10:10:34 AM

43021_FM.indd 2 9/10/07 10:10:34 AM

CRC Press is an imprint of the

Taylor & Francis Group, an informa business

Boca Raton London New York

Software

Solutions

for

Engineers

and

Scientists

Julio Sanchez

Maria P. Canton

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

43021_FM.indd 3 9/10/07 10:10:34 AM

CRC Press

Taylor & Francis Group

6000 Broken Sound Parkway NW, Suite 300

Boca Raton, FL 33487‑2742

© 2008 by Taylor & Francis Group, LLC

CRC Press is an imprint of Taylor & Francis Group, an Informa business

No claim to original U.S. Government works

Printed in the United States of America on acid‑free paper

10 9 8 7 6 5 4 3 2 1

International Standard Book Number‑13: 978‑1‑4200‑4302‑0 (Hardcover)

This book contains information obtained from authentic and highly regarded sources. Reprinted material is quoted

with permission, and sources are indicated. A wide variety of references are listed. Reasonable efforts have been made to

publish reliable data and information, but the author and the publisher cannot assume responsibility for the validity of

all materials or for the consequences of their use.

No part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or

other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any informa‑

tion storage or retrieval system, without written permission from the publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://

www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC) 222 Rosewood Drive, Danvers, MA 01923,

978‑750‑8400. CCC is a not‑for‑profit organization that provides licenses and registration for a variety of users. For orga‑

nizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for

identification and explanation without intent to infringe.

Library of Congress Cataloging‑in‑Publication Data

Sanchez, Julio, 1938‑

Software solutions for engineers and scientists / authors, Julio Sanchez and Maria P. Canton.

p. cm.

Includes bibliographical references and index.

ISBN 978‑1‑4200‑4302‑0 (alk. paper)

1. Engineering‑‑Data processing. 2. Science‑‑Data processing. I. Canton, Maria P. II. Title.

TA345.S31535 2008

620’.0285‑‑dc22 2007034749

Visit the Taylor & Francis Web site at

http://www.taylorandfrancis.com

and the CRC Press Web site at

http://www.crcpress.com

43021_FM.indd 4 9/10/07 10:10:34 AM

Table of Contents

Preface xxiii

PART I — TECHNIQUES AND CODE

Chapter 1 — Computer Number Systems

Chapter Summary 3

1.0 Counting 3

1.0.1 The Tally System 3

1.0.2 Roman Numerals 4

1.1 The Origins of Our Number System 5

1.1.1 Number Systems for Digital-Electronics 6

1.1.2 Positional Characteristics 7

1.1.3 Radix or Base 7

1.2 Types of Numbers 8

1.2.1 Whole Numbers 8

1.2.2 Signed Numbers 8

1.2.3 Rational and Irrational Numbers 8

1.2.4 Real and Complex Numbers 9

1.3 Radix Representations 10

1.3.1 Decimal Versus Binary Numbers 10

1.3.2 Octal and Hexadecimal Numbers 11

1.4 General Theory of Counting 12

1.5 Assembly Language Conversion Routines 14

1.5.1 Binary-to-ASCII-Decimal Conversion 15

1.5.2 Binary-to-Hexadecimal Conversion 18

1.5.3 Decimal-to-Binary Conversion 19

1.6 C++ Conversion Routines 23

1.6.1 C++ Binary-to-ASCII Conversions 23

1.6.2 C++ ASCII-to-Binary Conversions 25

Chapter 2 — Numeric Data in Memory

Chapter Summary 31

2.0 Electronic-Digital Machines 31

2.1 Storage of Numerical Data 32

2.1.1. Word Size 32

2.2 Integer Encodings 33

2.2.1 Sign-Magnitude Representation 34

2.2.2 Radix Complement Representation 35

2.3 Encoding of Fractional Numbers 39

2.3.1 Fixed Point Representations 40

v

2.3.2 Floating-Point Representations 41

2.4 Standardized Floating-Point Encodings 42

2.4.1 ANSI/IEEE 754 Single Format 42

2.4.2 Floating-Point Exponent in ANSI/IEEE 754 Single Format 43

2.4.3 Floating-Point Significand in ANSI/IEEE 754 Single Format 44

2.4.4 Decoding Floating-Point Numbers 45

2.5 Binary-Coded Decimals (BCD) 49

2.5.1 Floating-Point BCD 49

2.6 BCD Conversions 51

2.6.1 BCD Conversion Functions 51

Chapter 3 — Machine Arithmetic

Chapter Summary 55

3.0 Intel Microprocessors 55

3.0.1 CPU Flags 56

3.1 Logical Instructions 57

3.1.1 Logical AND 58

3.1.2 Logical OR 59

3.1.3 Logical XOR 59

3.1.4 Logical NOT 60

3.2 Arithmetic Instructions 60

3.2.1 Signed and Unsigned Arithmetic 60

3.2.2 Operations on Decimal Numbers 61

3.3 Auxiliary and Bit Manipulation Instructions 63

3.3.1 Bit Shift and Rotate Instructions 63

Bit Shift Instructions 63

Bit Rotate Instructions 66

Double Precision Shift Instructions 67

Shift and Rotate Addressing Modes 68

3.3.2 Comparison, Bit Scan, and Bit Test Instructions 68

Signed and Unsigned Conditional Jumps 70

3.3.3 Increment, Decrement, and Sign Extension Instructions 71

3.3.4 486 and Pentium Proprietary Instructions 72

BSWAP 72

XADD 73

CMPXCHG and CMPXCHG8B 74

3.4 CPU Identification 74

Chapter 4 — High-Precision Arithmetic

Chapter Summary 79

4.0 Applications of BCD Arithmetic 79

4.0.1 ANSI/IEEE 854 Standard 80

4.1 Algorithms for BCD Arithmetic 81

4.2 Floating-Point BCD Addition 82

4.3 Floating-Point BCD Subtraction 82

4.4 Floating-Point BCD Multiplication 83

4.5 Floating-Point BCD Division 85

4.6 C++ BCD Arithmetic Functions 86

4.6 High-Precision BCD Arithmetic 90

vi Table of Contents

Chapter 5 — Floating-Point Hardware

Chapter Summary 95

5.0 A Mathematical Coprocessor 95

5.1 Intel Math Units 96

5.1.1 Math Unit Applications 97

5.1.2 Math Unit Limitations 98

5.1.3 Processor/Coprocessor Interface 99

5.1.4 Math Unit Versions 100

8087 101

80287 101

80387 102

5.1.5 The Numeric Unit in 486 and Pentium CPU 102

5.2 Detecting and Identifying the Math Unit 102

5.3 ANSI/IEEE 754 Standard 106

5.3.1 Numeric Data Encoding 107

5.3.2 Rounding 109

5.3.3 Interval Arithmetic 110

5.3.4 Treatment of Infinity 110

5.3.5 Not a Number (NaN) 112

Signaling and Quiet NaNs 112

5.3.6 Exceptions 113

Invalid Operation Exception 113

Division by Zero Exception 114

Overflow Exception 114

Underflow Exception 115

Inexact Result Exception 116

Chapter 6 — Floating Point Data and Conversions

Chapter Summary 117

6.0 Math Unit Data Formats 117

6.0.1 Binary Integers 118

6.0.2 Decimal Integers 119

6.0.3 Binary Reals 120

6.1 Special Encodings for Reals 121

6.2 Low-Level Numeric Data in Memory 123

6.2.1 Initializing Data with the DW Directive 124

6.2.2 Initializing Data with DD and DQ Directives 124

6.2.3 Initializing Data with the DT Directive 125

6.2.4 Memory Image of the Special Encodings 125

6.2.5 Operating on Memory Variables 126

6.3 High-Level Numeric Data 127

6.4 Numeric Data Conversions 127

6.4.1 Data Conversion in ANSI/IEEE 754 128

6.4.2 Conversion Requirements in ANSI/IEEE 754 128

6.4.3 FPU_INPUT Procedure 130

Calculating 10y

131

Post-Conversion Operations 132

6.4.4 FPU_OUTPUT Procedure 132

6.4.5 ASCII-to-Exponential Conversion 133

6.5 High-Level Interface Functions 133

Table of Contents vii

Chapter 7 — Math Unit Architecture and Instruction Set

Chapter Summary 137

7.0 Math Unit Internal Organization 137

7.0.1 Math Unit Register Stack 137

7.0.2 Math Unit Control Register 140

Error Conditions 141

7.0.3 Math Unit Status Register 143

7.0.4 The Environment Area 150

Tag Word Register 152

Instruction and Data Pointers 154

7.0.5 Math Unit State Area 156

7.1 Math Unit Instruction Patterns 158

7.1.1 Register Operands 158

7.1.2 Memory Operands 159

7.2 Math Unit Instruction Set 159

7.2.1 Data Transfer Instructions 160

7.2.2 Nontranscendental Instructions 161

Basic Arithmetic 161

Scaling and Square Root 162

Partial Remainder 163

Update of the Partial Remainder 166

Manipulating the Encoding 168

7.2.3 Comparison Instructions 171

7.2.4 Transcendental Instructions 172

Transcendental Algorithms 174

7.2.5 Constant Instructions 177

7.2.6 Processor Control Instructions 178

Chapter 8 — Transcendental Primitives

Chapter Summary 181

8.0 Developing Math Unit Software 181

8.1 Exponential Functions 182

8.1.1 Calculation of Powers 183

Logarithmic Approximation of Exponentials 184

Binary Powering 186

Exponent Factoring 190

Applications 198

Mixed Methods 198

8.2 Math Unit Trigonometry 199

8.2.1 Angular Conversions 199

8.2.2 Range-Scaling Operations 201

Reduction to the Unit Circle 201

Reduction to the First Octant 202

8.2.3 Trigonometric Functions 204

Calculating Tangent, Sine, and Cosine 205

Trigonometric Arcfunctions 207

8.4 Logarithms 211

8.4.1 Calculating Natural and Common Logarithms 211

8.4.2 Calculating Antilogarithms 212

8.5 C++ Interface to Transcendentals 213

viii Table of Contents

Chapter 9 — General Mathematical Functions

Chapter Summary 215

9.0 Calculator Operations 215

9.0.1 Calculating Hyperbolic Functions 216

9.0.2 Factorial 220

9.0.3 Ordering Numeric Data 221

9.0.4 Calculating the Modulus 224

9.0.5 Integer and Fractional Parts 225

9.0.6 Solving Triangles 227

9.1 Quadratic Equations 229

9.2 Imaginary and Complex Numbers 232

9.2.1 Operations in Complex Arithmetic 233

9.2.2 Real and Complex Roots of a Quadratic Equation 240

9.2.3 Polar and Cartesian Coordinates 244

Chapter 10 — Financial Calculations

Chapter Summary 249

10.0 Interest Calculations 249

10.0.1 Simple Interest 249

10.0.2 Compound Interest 251

Future Value at Compound Interest 252

Exponentials in Financial Formulas 253

Present Value at Compound Interest 254

Effective Rate 256

10.1 Amortization 257

10.1.1 Periodic Payment Calculations 257

10.1.2 Add-On Interest 259

10.1.3 Annual Percentage Rate 261

10.2 Annuities 263

10.2.1 Annuity Future Value 263

10.2.2 Annuity Present Value 265

10.2.3 Annuity Due 266

10.2.4 Sinking Fund 269

10.2.5 Number of Compounding Periods 271

10.3 Numerical Errors in Financial Calculations 272

10.3.1 Conversion Errors 273

10.3.2 Representation Errors 273

10.3.3 Precision and Computation Errors 274

Cancellation Error 275

10.4 Financial Software 275

Chapter 11 — Statistical Calculations

Chapter Summary 277

11.0 About Statistical Data 277

11.0.1 Data-Type-Flexible Coding 278

11.1 Data Manipulation Primitives 278

11.1.1 Common Summations 278

11.1.2 Sorting 280

11.2 Counting Techniques 281

Table of Contents ix

11.2.1 Permutations 282

11.2.2 Combinations 283

11.2.3 Binomial Probability 285

11.3 Measures of Central Tendency 286

11.3.1 Mean 287

11.3.2 Median 287

11.3.3 Midrange 288

11.3.4 Mode 289

11.3.5 Weighted Measures of Central Tendency 292

11.4 Measures of Dispersion 294

11.4.1 Range 294

11.4.2 Variance 295

11.4.3 Standard Deviation 296

11.5 Normal Distribution 297

11.5.1 Normal Curve 297

Standard Normal Curve 298

11.5.2 Calculating f(x) 299

11.5.3 Probability in Normal Distribution 301

11.6 Linear Correlation and Regression 304

11.6.1 Linear Correlation Coefficient 305

11.6.2 Linear Regression Analysis 307

Chapter 12 — Interpolation, Differentiation, and Integration

Chapter Summary 311

12.0 Interpolation 311

12.0.1 Linear Interpolation 313

12.0.2 Lagrange Interpolation 316

12.0.3 Least-Squares Interpolation 319

Linear Models 319

Calculating the Error Sum 321

Least-Squares Linear Interpolation Function 321

Non-Linear Models 323

12.1 Numerical Differentiation 327

12.2 Numerical Integration 332

12.2.1 Integration by the Trapezoidal Rule 333

12.2.2 Integration by Simpson's Rule 336

Chapter 13 — Linear Systems

Chapter Summary 341

13.0 Linear Equations 341

13.0.1 Systems of Linear Equations 342

13.0.2 Matrix Representations of Linear Systems 344

13.1 Numeric Data in Matrix Form 345

13.1.1 Matrices in C++ 345

13.1.2 Locating a Matrix Entry 348

13.2 Operations on Matrix Entries 349

13.2.1 Vectors 350

13.2.2 Vector-by-Scalar Operations in C++ 350

13.2.3 Low-Level Vector-by-Scalar Operations 352

13.2.4 Matrix-by-Scalar Operations 357

x Table of Contents

13.2.5 Matrix-by-Matrix Operations 359

Matrix Addition 360

Matrix Multiplication 363

13.3 The Solution of a Linear System 368

13.3.1 Gauss-Jordan Elimination 368

13.3.2 Errors in Gaussian Elimination 370

13.4 A Gauss-Jordan Algorithm 371

13.5 Solution of a Linear System 372

Chapter 14 — Solving and Parsing Equations

Chapter Summary 375

14.0 Function Mapping 375

14.1 Developing a Parser 377

14.2 Evaluating User Equations 379

14.2.1 Equation Grammar 379

14.2.2 Equation Syntax 380

14.2.3 Symbol Table and Numeric Data 381

14.3 An Equation-Solving Algorithm 382

14.3.1 The _EVALUATE Procedure 382

14.3.2 _CALCULATE_Y Procedure 386

Chapter 15 — Neural Networks

Chapter Summary 389

15.0 Reverse-Engineering the Brain 389

15.0.1 The Biological Neuron 389

15.0.2 The Artificial Neuron 391

15.0.3 Artificial Neural Networks 394

15.1 The Network as a Classifier 396

15.1.1 Multiple-Node Networks 396

15.1.2 Software Model for Neural Nets 398

15.2 The Perceptron 398

15.2.1 Perceptron as a Classifier 399

15.2.2 Perceptron Learning 400

15.2.3 Training the Perceptron 402

15.2.4 A Perceptron Function 403

15.3 The Adaline 405

15.3.1 Widrow-Hoff Learning 405

15.3.2 A Neuron for Adaline 406

15.4 Improving the Classification Function 409

15.4.1 Calculating the Error Sum 409

15.4.2 Improving Perceptron Results 410

15.5 Backpropagation Networks 412

15.5.1 Nonlinear Neurons 413

15.5.2 Backpropagation Algorithm 414

15.5.3 Software Model for Backpropagation 415

15.5.4 Executing the Network 417

15.5.5 A Backpropagation Trainer 418

Table of Contents xi

PART II — APPLICATION DEVELOPMENT

Chapter 16 — The C++ Language on the PC

Chapter Summary 423

16.0 Introducing C++ 423

16.0.1 Evolution of C++ 423

16.0.2 Advantages of the C++ Language 424

16.0.3 Disadvantages of the C++ Language 424

16.1 PC Implementations of C and C++ 425

16.2 Flowcharts and Software Design 425

16.3 The C++ Console Application 427

Chapter 17 — Event-Driven Programming

Chapter Summary 431

17.0 Graphical Operating Systems 431

17.1 Enter Windows 432

17.1.1 Text-based and Graphical Programs 432

17.1.2 Graphics Services 434

17.2 Programming Models 434

17.2.1 Event-Driven Programs 434

The Event Manager 436

The Event Handler 436

17.2.2 Event Types 436

System Events 436

Control Events 437

Program Events 437

17.2.3 Event Modeling 437

17.3 File Structure of a Windows Program 438

17.3.1 Source Files 438

17.3.2 Library Files 439

17.3.3 Resource Files 440

17.3.4 Make Files 440

17.3.5 Object Files 441

17.3.6 Executable Files 442

17.3.7 Dynamic Linking 444

Chapter 18 — The Window Program Components

Chapter Summary 447

18.0 “Hello, World” 447

18.1 Naming Conventions 449

18.2 Constants and Handles 451

18.2.1 Windows Handles 452

18.3 Visual Elements 453

18.3.1 The Main Window 453

18.3.2 Controls 454

18.3.3 Other Visual Components 455

18.4 Programming Style 456

18.4.1 Commented Headers 456

xii Table of Contents

18.4.2 Assertions Notation 457

ASSERT 458

INV 458

PRE and POST 458

FCTVAL 458

18.4.3 Programming Templates 458

Chapter 19 — A First Windows Program

Chapter Summary 463

19.0 Preliminary Steps 463

19.1 The Program Project 464

19.1.1 Creating a Project 464

19.2 Elements of a Windows Program 468

19.2.1 WinMain() 468

Parameters 469

19.2.2 Data Variables 470

19.2.3 WNDCLASSEX Structure 471

19.2.4 Registering the Windows Class 475

19.2.5 Creating the Window 476

19.2.6 Displaying the Window 480

19.2.7 The Message Loop 480

19.3 The Window Procedure 481

19.3.1 Windows Procedure Parameters 482

19.3.2 Windows Procedure Variables 483

19.3.3 Message Processing 483

WM_CREATE Message Processing 484

WM_PAINT Message Processing 484

WM_DESTROY Message Processing 485

19.3.4 The Default Windows Procedure 485

19.4 The WinHello Program 486

19.4.1 Modifying the Program Caption 486

19.4.2 Displaying Text in the Client Area 487

19.4.3 Creating a Program Resource 489

19.4.4 Creating the Icon Bitmap 490

19.5 WinHello Program Listing 493

Chapter 20 — Text Display

Chapter Summary 497

20.0 Text in Windows 497

20.1 The Client Area 498

20.2 Device and Display Contexts 498

20.2.1 The Display Context 499

20.2.2 Display Context Types 500

20.2.3 Window Display Context 502

20.3 Mapping Modes 502

20.3.1 Screen and Client Area 503

20.3.2 Viewport and Window 504

20.4 Programming Text Operations 505

20.4.1 Typefaces and Fonts 507

20.4.2 Text Formatting 508

Table of Contents xiii

20.4.3 Paragraph Formatting 511

20.4.4 The DrawText() Function 515

20.5 Text Graphics 518

20.5.1 Selecting a Font 518

20.5.2 Drawing with Text 523

Chapter 21 — Keyboard and Mouse Programming

Chapter Summary 525

21.0 Keyboard Input 525

21.1 Input Focus 526

21.1.1 Keystroke Processing 527

21.1.2 Determining the Key State 529

21.1.3 Character Code Processing 530

21.1.4 Keyboard Demonstration Program 531

21.2 The Caret 534

21.2.1 Caret Processing 535

21.2.2 Caret Demonstration Program 535

21.3 Mouse Programming 538

21.3.1 Mouse Messages 539

21.3.2 Cursor Location 541

21.3.3 Double-Click Processing 542

21.3.4 Capturing the Mouse 543

21.3.5 The Cursor 543

21.4 Mouse and Cursor Demonstration Program 546

Chapter 22 — Graphical User Interface Elements

Chapter Summary 549

22.0 Window Styles 549

22.1 Child Windows 550

22.1.1 Child Windows Demonstration Program 552

22.2 Basic Controls 554

22.2.1 Communicating with Controls 558

22.2.2 Controls Demonstration Program 563

22.3 Menus 566

22.3.1 Creating a Menu 568

22.3.2 Menu Item Processing 569

22.3.3 Shortcut Keys 570

22.3.4 Pop-Up Menus 571

22.3.5 The Menu Demonstration Program 573

22.4 Dialog Boxes 573

22. 4. 1 Modal and Modeless 574

22. 4. 2 The Message Box 574

22.4.3 Creating a Modal Dialog Box 576

22.4.4 Common Dialog Boxes 578

22.4.5 The Dialog Box Demonstration Program 581

22.5 Common Controls 581

22.5.1 Common Controls Message Processing 582

22.5.2 Toolbars and ToolTips 583

22.5.3 Creating a Toolbar 584

22.5.4 Standard Toolbar Buttons 589

xiv Table of Contents

Tải ngay đi em, còn do dự, trời tối mất!