Introduction to Scientific Programming in C++17/Fortran2003

Total Page:16

File Type:pdf, Size:1020Kb

Introduction to Scientific Programming in C++17/Fortran2003 Introduction to Scientific Programming in C++17/Fortran2003 Victor Eijkhout 2017-2021, last formatted September 14, 2021 2 Introduction to Scientific Programming Contents I Introduction 19 1 Introduction 21 1.1 Programming and computational thinking 21 1.1.1 History 21 1.1.2 Is programming science, art, or craft? 22 1.1.3 Computational thinking 23 1.1.4 Hardware 25 1.1.5 Algorithms 25 1.2 About the choice of language 26 2 Warming up 29 2.1 Programming environment 29 2.1.1 Language support in your editor 29 2.2 Compiling 30 2.3 Your environment 30 3 Teachers guide 31 3.1 Justification 31 3.2 Timeline for a C++/F03 course 32 3.2.1 Advanced topics 32 3.2.2 Project-based teaching 32 3.2.3 Choice: Fortran or advanced topics 32 3.3 Scaffolding 35 3.4 Grading guide 35 3.4.1 Code layout and naming 35 3.4.2 Basic elements 36 3.4.3 Conditionals 36 3.4.4 Looping 36 3.4.5 Functions 36 3.4.6 Scope 36 3.4.7 Structures 37 3.4.8 Classes 37 3.4.9 Arrays and vectors 37 3.4.10 Strings 37 3.4.11 Other remarks 37 3 Contents II C++ 39 4 Basic elements of C++ 41 4.1 From the ground up: Compiling C++ 41 4.1.1 A quick word about unix commands 42 4.1.2 C++ is a moving target 43 4.2 Statements 43 4.3 Variables 44 4.3.1 Variable declarations 45 4.3.2 Assignments 46 4.3.3 Terminal input 47 4.3.4 Datatypes 47 4.3.5 Complex numbers 50 4.3.6 Initialization 50 4.4 Input/Output, or I/O as we say 50 4.5 Expressions 50 4.5.1 Numbers 51 4.5.2 Numerical expressions 51 4.5.3 Truth values 52 4.5.4 Type conversions 52 4.6 Advanced topics 54 4.6.1 Integer precision 54 4.6.2 Unsigned types 54 4.6.3 The main program and the return statement 54 4.6.4 Number values and undefined values 55 4.6.5 Constants 55 4.6.6 Numerical precision 56 4.7 Review questions 56 5 Conditionals 57 5.1 Conditionals 57 5.2 Operators 58 5.3 Switch statement 60 5.4 Scopes 61 5.5 Advanced topics 61 5.5.1 Short-circuit evaluation 61 5.5.2 Ternary if 61 5.5.3 Initializer 62 5.6 Review questions 62 6 Looping 65 6.1 The ‘for’ loop 65 6.1.1 Loop syntax 69 6.2 Looping until 70 6.3 Advanced topics 73 6.3.1 Parallelism 73 6.4 Exercises 74 7 Functions 75 7.1 Function definition and call 75 4 Introduction to Scientific Programming Contents 7.1.1 Why use functions? 77 7.2 Anatomy of a function definition and call 79 7.2.1 Another option for defining functions 80 7.3 Void functions 80 7.4 Parameter passing 81 7.4.1 Pass by value 81 7.4.2 Pass by reference 83 7.5 Recursive functions 86 7.6 Other function topics 88 7.6.1 Math functions 88 7.6.2 Default arguments 88 7.6.3 Polymorphic functions 89 7.6.4 Stack overflow 89 7.7 Review questions 90 7.7.1 Eight queens 91 8 Scope 93 8.1 Scope rules 93 8.1.1 Lexical scope 93 8.1.2 Shadowing 93 8.1.3 Lifetime versus reachability 94 8.1.4 Scope subtleties 95 8.2 Static variables 96 8.3 Scope and memory 97 8.4 Review questions 97 9 Classes and objects 99 9.1 What is an object? 99 9.1.1 First examples: points in the plane 99 9.1.2 Constructor 101 9.1.3 Data members, introduction 101 9.1.4 Methods, introduction 102 9.1.5 Initialization 103 9.1.6 Methods 104 9.1.7 Default constructor 106 9.1.8 Accessors 107 9.1.9 Examples 108 9.2 Inclusion relations between classes 109 9.2.1 Literal and figurative has-a 109 9.3 Inheritance 110 9.3.1 Methods of base and derived classes 112 9.3.2 Virtual methods 112 9.3.3 Friend classes 113 9.3.4 Multiple inheritance 114 9.4 Advanced topics 114 9.4.1 Class prototypes 114 9.4.2 Returning by reference 115 9.4.3 Accessor functions 115 Victor Eijkhout 5 Contents 9.4.4 Polymorphism 116 9.4.5 Operator overloading 116 9.4.6 Copy constructor 118 9.4.7 Destructor 119 9.4.8 ‘this’ pointer 121 9.4.9 Static members 122 9.5 Review question 123 10 Arrays 125 10.1 Some simple examples 125 10.1.1 Vector creation 125 10.1.2 Initialization 126 10.1.3 Element access 127 10.1.4 Access out of bounds 127 10.2 Going over all array elements 129 10.2.1 Ranging over a vector 129 10.2.2 Ranging over the indices 129 10.2.3 Ranging by reference 130 10.3 Vector are a class 131 10.3.1 Vector methods 132 10.3.2 Vectors are dynamic 132 10.4 Vectors and functions 133 10.4.1 Pass vector to function 134 10.4.2 Vector as function return 135 10.5 Vectors in classes 136 10.5.1 Timing 137 10.6 Wrapping a vector in an object 138 10.7 Multi-dimensional cases 138 10.7.1 Matrix as vector of vectors 139 10.7.2 A better matrix class 139 10.8 Advanced topics 140 10.8.1 Iterators 140 10.8.2 Old-style arrays 141 10.8.3 Stack and heap allocation 143 10.8.4 The Array class 144 10.8.5 Span 144 10.9 Exercises 145 11 Strings 149 11.1 Characters 149 11.2 Basic string stuff 149 11.3 String streams 153 11.4 Advanced topics 153 11.4.1 Raw string literals 153 11.4.2 Conversation to/from string 153 11.4.3 Unicode 154 11.5 C strings 154 12 Input/output 155 6 Introduction to Scientific Programming Contents 12.1 Screen output 155 12.1.1 Floating point output 158 12.1.2 Saving and restoring settings 159 12.2 File output 160 12.3 Output your own classes 160 12.4 Output buffering 161 12.4.1 The need for flushing 161 12.4.2 Performance considerations 161 12.5 Input 162 12.5.1 File input 162 12.5.2 Input streams 163 13 Lambda functions 165 13.1 Passing lambdas around 166 13.1.1 Lambda members of classes 166 13.2 Captures 167 13.3 Capture by reference 167 13.4 More 168 13.4.1 Generic lambdas 168 13.4.2 Algorithms 168 13.4.3 C-style function pointers 168 14 Iterators, Algorithms, Ranges 169 14.1 Iterators 169 14.1.1 Iterators 169 14.1.2 Simple iterating, the hard way 170 14.1.3 Forming sub-arrays 170 14.1.4 Vector operations through iterators 171 14.2 Algorithms 172 14.2.1 Any/all/each 172 14.2.2 Reduction 173 14.3 Ranges 174 14.3.1 Infinite sequences 176 15 References 177 15.1 Reference 177 15.2 Pass by reference 177 15.3 Reference to class members 178 15.4 Reference to array members 180 15.5 rvalue references 181 16 Pointers 183 16.1 The ‘arrow’ notation 183 16.2 Making a shared pointer 184 16.2.1 Pointers and arrays 185 16.2.2 Smart pointers versus address pointers 186 16.3 Garbage collection 187 16.4 More about pointers 188 16.4.1 Get the pointed data 188 16.5 Advanced topics 189 Victor Eijkhout 7 Contents 16.5.1 Unique pointers 189 16.5.2 Base and derived pointers 189 16.5.3 Shared pointer to ‘this’ 189 16.5.4 Weak pointers 190 16.5.5 Null pointer 191 16.5.6 Opaque pointer 191 16.5.7 Pointers to non-objects 191 16.6 Smart pointers vs C pointers 192 17 C-style pointers and arrays 193 17.1 What is a pointer 193 17.2 Pointers and addresses, C style 193 17.3 Arrays and pointers 195 17.4 Pointer arithmetic 197 17.5 Multi-dimensional arrays 197 17.6 Parameter passing 197 17.6.1 Allocation 198 17.6.2 Use of new 200 17.7 Memory leaks 201 17.8 Const pointers 201 18 Const 203 18.1 Const arguments 203 18.2 Const references 203 18.2.1 Const references in range-based loops 205 18.3 Const methods 205 18.4 Overloading on const 205 18.5 Const and pointers 206 18.5.1 Old-style const pointers 207 18.6 Mutable 208 18.7 Compile-time constants 209 19 Prototypes and header files 211 19.1 Include files 211 19.2 Prototypes for functions 212 19.2.1 Separate compilation 213 19.2.2 Header files 213 19.2.3 C and C++ headers 214 19.3 Prototypes for class methods 215 19.4 Header files and templates 215 19.5 Namespaces and header files 216 19.6 Global variables and header files 216 19.7 Modules 217 20 Namespaces 219 20.1 Solving name conflicts 219 20.1.1 Namespace header files 220 20.2 Best practices 221 21 Preprocessor 223 21.1 Include files 223 8 Introduction to Scientific Programming Contents 21.1.1 Kinds of includes 223 21.1.2 Search paths 224 21.2 Textual substitution 224 21.2.1 Dynamic definition of macros 225 21.2.2 A new use for ‘using’ 225 21.2.3 Parametrized macros 225 21.3 Conditionals 226 21.3.1 Check on a value 226 21.3.2 Check for macros 226 21.3.3 Including a file only once 226 21.4 Other pragmas 227 22 Templates 229 22.1 Templated functions 229 22.2 Templated classes 230 22.2.1 Specific implementation 230 22.3 Example 230 22.4 Concepts 232 23 Error handling 233 23.1 General discussion 233 23.2 Mechanisms to support error handling and debugging 234 23.2.1 Assertions 234 23.2.2 Exception handling 235 23.2.3 ‘Where does this error come from’ 238 23.2.4 Legacy mechanisms 238 23.2.5 Legacy C mechanisms 238 23.3 Tools 238 24 Standard Template Library 239 24.1 Complex numbers 239 24.2 Containers 240 24.2.1 Maps: associative arrays 240 24.3 Regular expression 241 24.3.1 Regular expression syntax 242 24.4 Tuples and structured bindings 242 24.5 Union-like stuff: tuples, optionals, variants 243 24.5.1 Tuples 243 24.5.2 Optional 244 24.5.3 Variant 244 24.5.4 Any 246 24.6 Limits 246 24.7 Common numbers 248 24.8 Random numbers 248 24.8.1 C random function 249 24.9 Time 250 24.10 File system 251 24.11 Regular expressions 251 24.12 Enum classes 251 Victor Eijkhout 9 Contents 25 Concurrency 253 25.1 Thread creation 253 25.2 Synchronization 253 26 Obscure stuff 255 26.1 Auto 255 26.1.1 Declarations 255 26.1.2 Auto and function definitions 256 26.1.3 decltype: declared type 256 26.2 Iterating over classes 257 26.3 Casts 260 26.3.1 Static cast 260 26.3.2 Dynamic cast 261 26.3.3 Const cast 262 26.3.4 Reinterpret cast 262 26.3.5 A word about void pointers 262 26.4 lvalue vs rvalue 263 26.4.1 Conversion 264 26.4.2 References 264 26.4.3 Rvalue references 264 26.5 Move semantics 265 26.6 Graphics 265 26.7 Standards timeline 266 26.7.1 C++98/C++03 266 26.7.2 C++11 266 26.7.3 C++14 266 26.7.4 C++17 267 26.7.5 C++20 267 27 Graphics 269 28 C++ for C programmers 271 28.1 I/O 271 28.2 Arrays 271 28.2.1 Vectors from C arrays 271 28.3 Dynamic storage 272 28.4 Strings 272
Recommended publications
  • Plotting Direction Fields in Matlab and Maxima – a Short Tutorial
    Plotting direction fields in Matlab and Maxima – a short tutorial Luis Carvalho Introduction A first order differential equation can be expressed as dx x0(t) = = f(t; x) (1) dt where t is the independent variable and x is the dependent variable (on t). Note that the equation above is in normal form. The difficulty in solving equation (1) depends clearly on f(t; x). One way to gain geometric insight on how the solution might look like is to observe that any solution to (1) should be such that the slope at any point P (t0; x0) is f(t0; x0), since this is the value of the derivative at P . With this motivation in mind, if you select enough points and plot the slopes in each of these points, you will obtain a direction field for ODE (1). However, it is not easy to plot such a direction field for any function f(t; x), and so we must resort to some computational help. There are many computational packages to help us in this task. This is a short tutorial on how to plot direction fields for first order ODE’s in Matlab and Maxima. Matlab Matlab is a powerful “computing environment that combines numeric computation, advanced graphics and visualization” 1. A nice package for plotting direction field in Matlab (although resourceful, Matlab does not provide such facility natively) can be found at http://math.rice.edu/»dfield, contributed by John C. Polking from the Dept. of Mathematics at Rice University. To install this add-on, simply browse to the files for your version of Matlab and download them.
    [Show full text]
  • TI 83/84: Scientific Notation on Your Calculator
    TI 83/84: Scientific Notation on your calculator this is above the comma, next to the square root! choose the proper MODE : Normal or Sci entering numbers: 2.39 x 106 on calculator: 2.39 2nd EE 6 ENTER reading numbers: 2.39E6 on the calculator means for us. • When you're in Normal mode, the calculator will write regular numbers unless they get too big or too small, when it will switch to scientific notation. • In Sci mode, the calculator displays every answer as scientific notation. • In both modes, you can type in numbers in scientific notation or as regular numbers. Humans should never, ever, ever write scientific notation using the calculator’s E notation! Try these problems. Answer in scientific notation, and round decimals to two places. 2.39 x 1016 (5) 2.39 x 109+ 4.7 x 10 10 (4) 4.7 x 10−3 3.01 103 1.07 10 0 2.39 10 5 4.94 10 10 5.09 1018 − 3.76 10−− 1 2.39 10 5 7.93 10 8 Remember to change your MODE back to Normal when you're done. Using the STORE key: Let's say that you want to store a number so that you can use it later, or that you want to store answers for several different variables, and then use them together in one problem. Here's how: Enter the number, then press STO (above the ON key), then press ALPHA and the letter you want. (The letters are in alphabetical order above the other keys.) Then press ENTER.
    [Show full text]
  • Primitive Number Types
    Primitive number types Values of each of the primitive number types Java has these 4 primitive integral types: byte: A value occupies 1 byte (8 bits). The range of values is -2^7..2^7-1, or -128..127 short: A value occupies 2 bytes (16 bits). The range of values is -2^15..2^15-1 int: A value occupies 4 bytes (32 bits). The range of values is -2^31..2^31-1 long: A value occupies 8 bytes (64 bits). The range of values is -2^63..2^63-1 and two “floating-point” types, whose values are approximations to the real numbers: float: A value occupies 4 bytes (32 bits). double: A value occupies 8 bytes (64 bits). Values of the integral types are maintained in two’s complement notation (see the dictionary entry for two’s complement notation). A discussion of floating-point values is outside the scope of this website, except to say that some bits are used for the mantissa and some for the exponent and that infinity and NaN (not a number) are both floating-point values. We don’t discuss this further. Generally, one uses mainly types int and double. But if you are declaring a large array and you know that the values fit in a byte, you can save ¾ of the space using a byte array instead of an int array, e.g. byte[] b= new byte[1000]; Operations on the primitive integer types Types byte and short have no operations. Instead, operations on their values int and long operations are treated as if the values were of type int.
    [Show full text]
  • CAS (Computer Algebra System) Mathematica
    CAS (Computer Algebra System) Mathematica- UML students can download a copy for free as part of the UML site license; see the course website for details From: Wikipedia 2/9/2014 A computer algebra system (CAS) is a software program that allows [one] to compute with mathematical expressions in a way which is similar to the traditional handwritten computations of the mathematicians and other scientists. The main ones are Axiom, Magma, Maple, Mathematica and Sage (the latter includes several computer algebras systems, such as Macsyma and SymPy). Computer algebra systems began to appear in the 1960s, and evolved out of two quite different sources—the requirements of theoretical physicists and research into artificial intelligence. A prime example for the first development was the pioneering work conducted by the later Nobel Prize laureate in physics Martin Veltman, who designed a program for symbolic mathematics, especially High Energy Physics, called Schoonschip (Dutch for "clean ship") in 1963. Using LISP as the programming basis, Carl Engelman created MATHLAB in 1964 at MITRE within an artificial intelligence research environment. Later MATHLAB was made available to users on PDP-6 and PDP-10 Systems running TOPS-10 or TENEX in universities. Today it can still be used on SIMH-Emulations of the PDP-10. MATHLAB ("mathematical laboratory") should not be confused with MATLAB ("matrix laboratory") which is a system for numerical computation built 15 years later at the University of New Mexico, accidentally named rather similarly. The first popular computer algebra systems were muMATH, Reduce, Derive (based on muMATH), and Macsyma; a popular copyleft version of Macsyma called Maxima is actively being maintained.
    [Show full text]
  • C++ Data Types
    Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 2 (Part II) Introduction to C++ The char Data Type (Sample Program) Character and String Constants The char Data Type Program 2-12 assigns character constants to the variable letter. Anytime a program works with a character, it internally works with the code used to represent that character, so this program is still assigning the values 65 and 66 to letter. Character constants can only hold a single character. To store a series of characters in a constant we need a string constant. In the following example, 'H' is a character constant and "Hello" is a string constant. Notice that a character constant is enclosed in single quotation marks whereas a string constant is enclosed in double quotation marks. cout << ‘H’ << endl; cout << “Hello” << endl; The char Data Type Strings, which allow a series of characters to be stored in consecutive memory locations, can be virtually any length. This means that there must be some way for the program to know how long the string is. In C++ this is done by appending an extra byte to the end of string constants. In this last byte, the number 0 is stored. It is called the null terminator or null character and marks the end of the string. Don’t confuse the null terminator with the character '0'. If you look at Appendix A you will see that the character '0' has ASCII code 48, whereas the null terminator has ASCII code 0.
    [Show full text]
  • Floating Point Numbers
    Floating Point Numbers CS031 September 12, 2011 Motivation We’ve seen how unsigned and signed integers are represented by a computer. We’d like to represent decimal numbers like 3.7510 as well. By learning how these numbers are represented in hardware, we can understand and avoid pitfalls of using them in our code. Fixed-Point Binary Representation Fractional numbers are represented in binary much like integers are, but negative exponents and a decimal point are used. 3.7510 = 2+1+0.5+0.25 1 0 -1 -2 = 2 +2 +2 +2 = 11.112 Not all numbers have a finite representation: 0.110 = 0.0625+0.03125+0.0078125+… -4 -5 -8 -9 = 2 +2 +2 +2 +… = 0.00011001100110011… 2 Computer Representation Goals Fixed-point representation assumes no space limitations, so it’s infeasible here. Assume we have 32 bits per number. We want to represent as many decimal numbers as we can, don’t want to sacrifice range. Adding two numbers should be as similar to adding signed integers as possible. Comparing two numbers should be straightforward and intuitive in this representation. The Challenges How many distinct numbers can we represent with 32 bits? Answer: 232 We must decide which numbers to represent. Suppose we want to represent both 3.7510 = 11.112 and 7.510 = 111.12. How will the computer distinguish between them in our representation? Excursus – Scientific Notation 913.8 = 91.38 x 101 = 9.138 x 102 = 0.9138 x 103 We call the final 3 representations scientific notation. It’s standard to use the format 9.138 x 102 (exactly one non-zero digit before the decimal point) for a unique representation.
    [Show full text]
  • Floating Point Numbers and Arithmetic
    Overview Floating Point Numbers & • Floating Point Numbers Arithmetic • Motivation: Decimal Scientific Notation – Binary Scientific Notation • Floating Point Representation inside computer (binary) – Greater range, precision • Decimal to Floating Point conversion, and vice versa • Big Idea: Type is not associated with data • MIPS floating point instructions, registers CS 160 Ward 1 CS 160 Ward 2 Review of Numbers Other Numbers •What about other numbers? • Computers are made to deal with –Very large numbers? (seconds/century) numbers 9 3,155,760,00010 (3.1557610 x 10 ) • What can we represent in N bits? –Very small numbers? (atomic diameter) -8 – Unsigned integers: 0.0000000110 (1.010 x 10 ) 0to2N -1 –Rationals (repeating pattern) 2/3 (0.666666666. .) – Signed Integers (Two’s Complement) (N-1) (N-1) –Irrationals -2 to 2 -1 21/2 (1.414213562373. .) –Transcendentals e (2.718...), π (3.141...) •All represented in scientific notation CS 160 Ward 3 CS 160 Ward 4 Scientific Notation Review Scientific Notation for Binary Numbers mantissa exponent Mantissa exponent 23 -1 6.02 x 10 1.0two x 2 decimal point radix (base) “binary point” radix (base) •Computer arithmetic that supports it called •Normalized form: no leadings 0s floating point, because it represents (exactly one digit to left of decimal point) numbers where binary point is not fixed, as it is for integers •Alternatives to representing 1/1,000,000,000 –Declare such variable in C as float –Normalized: 1.0 x 10-9 –Not normalized: 0.1 x 10-8, 10.0 x 10-10 CS 160 Ward 5 CS 160 Ward 6 Floating
    [Show full text]
  • Sage Tutorial (Pdf)
    Sage Tutorial Release 9.4 The Sage Development Team Aug 24, 2021 CONTENTS 1 Introduction 3 1.1 Installation................................................4 1.2 Ways to Use Sage.............................................4 1.3 Longterm Goals for Sage.........................................5 2 A Guided Tour 7 2.1 Assignment, Equality, and Arithmetic..................................7 2.2 Getting Help...............................................9 2.3 Functions, Indentation, and Counting.................................. 10 2.4 Basic Algebra and Calculus....................................... 14 2.5 Plotting.................................................. 20 2.6 Some Common Issues with Functions.................................. 23 2.7 Basic Rings................................................ 26 2.8 Linear Algebra.............................................. 28 2.9 Polynomials............................................... 32 2.10 Parents, Conversion and Coercion.................................... 36 2.11 Finite Groups, Abelian Groups...................................... 42 2.12 Number Theory............................................. 43 2.13 Some More Advanced Mathematics................................... 46 3 The Interactive Shell 55 3.1 Your Sage Session............................................ 55 3.2 Logging Input and Output........................................ 57 3.3 Paste Ignores Prompts.......................................... 58 3.4 Timing Commands............................................ 58 3.5 Other IPython
    [Show full text]
  • Princeton University COS 217: Introduction to Programming Systems C Primitive Data Types
    Princeton University COS 217: Introduction to Programming Systems C Primitive Data Types Type: int Description: A (positive or negative) integer. Size: System dependent. On CourseLab with gcc217: 4 bytes. Example Variable Declarations: int iFirst; signed int iSecond; Example Literals (assuming size is 4 bytes): C Literal Binary Representation Note 123 00000000 00000000 00000000 01111011 decimal form -123 11111111 11111111 11111111 10000101 negative form 0173 00000000 00000000 00000000 01111011 octal form 0x7B 00000000 00000000 00000000 01111011 hexadecimal form 2147483647 01111111 11111111 11111111 11111111 largest -2147483648 10000000 00000000 00000000 00000000 smallest Type: unsigned int Description: A non-negative integer. Size: System dependent. sizeof(unsigned int) == sizeof(int). On CourseLab with gcc217: 4 bytes. Example Variable Declaration: unsigned int uiFirst; unsigned uiSecond; Example Literals (assuming size is 4 bytes): C Literal Binary Representation Note 123U 00000000 00000000 00000000 01111011 decimal form 0173U 00000000 00000000 00000000 01111011 octal form 0x7BU 00000000 00000000 00000000 01111011 hexadecimal form 4294967295U 11111111 11111111 11111111 11111111 largest 0U 00000000 00000000 00000000 00000000 smallest Type: long Description: A (positive or negative) integer. Size: System dependent. sizeof(long) >= sizeof(int). On CourseLab with gcc217: 8 bytes. Example Variable Declarations: long lFirst; long int iSecond; signed long lThird; signed long int lFourth; Page 1 of 5 Example Literals (assuming size is 8 bytes):
    [Show full text]
  • 36 Scientific Notation
    36 Scientific Notation Scientific notation is used to express extremely large or extremely small numbers efficiently. The main idea is to write the number you want as a number between 1 and 10 multiplied by an integer power of 10. Fill in the blanks in the table below. Write the decimal form of the number given in scientific notation. Then give the calculator’s notation for the scientific notation. This is the only time you should write this calculator notation. Calculator notation is not acceptable in your written work; use a human language! The last column is for a word name for the number. In a few rows, you will write the scientific notation yourself. Scientific Decimal Notation Calculator Word name for the notation notation number One billion one billion dollars dollars 1.0 ×10 9 dollars One year 3.16 ×10 7 seconds Distance from earth to moon 3.8 ×10 8 meters 6.24 ×10 23 Mass of Mars 624 sextillion kg kilograms 1.0 ×10 -9 Nanosecond seconds 8 Speed of tv 3.0 ×10 signals meters/second -27 -27 Atomic mass 1.66 ×10 Just say, “1.66 ×10 unit kilograms kg”! × 12 Light year 6 10 miles 15 Light year 9.5 ×10 meters One billion light years meters 16 Parsec 3.1 ×10 meters 6 Megaparsec 10 parsecs Megabyte = 220 = 1,048,576 20 2 bytes bytes bytes Micron One millionth of a meter The number of About one hundred stars in the billion Milky Way -14 Diameter of a 7.5 ×10 carbon-12 meters atom Rosalie A.
    [Show full text]
  • Highlighting Wxmaxima in Calculus
    mathematics Article Not Another Computer Algebra System: Highlighting wxMaxima in Calculus Natanael Karjanto 1,* and Husty Serviana Husain 2 1 Department of Mathematics, University College, Natural Science Campus, Sungkyunkwan University Suwon 16419, Korea 2 Department of Mathematics Education, Faculty of Mathematics and Natural Science Education, Indonesia University of Education, Bandung 40154, Indonesia; [email protected] * Correspondence: [email protected] Abstract: This article introduces and explains a computer algebra system (CAS) wxMaxima for Calculus teaching and learning at the tertiary level. The didactic reasoning behind this approach is the need to implement an element of technology into classrooms to enhance students’ understanding of Calculus concepts. For many mathematics educators who have been using CAS, this material is of great interest, particularly for secondary teachers and university instructors who plan to introduce an alternative CAS into their classrooms. By highlighting both the strengths and limitations of the software, we hope that it will stimulate further debate not only among mathematics educators and software users but also also among symbolic computation and software developers. Keywords: computer algebra system; wxMaxima; Calculus; symbolic computation Citation: Karjanto, N.; Husain, H.S. 1. Introduction Not Another Computer Algebra A computer algebra system (CAS) is a program that can solve mathematical problems System: Highlighting wxMaxima in by rearranging formulas and finding a formula that solves the problem, as opposed to Calculus. Mathematics 2021, 9, 1317. just outputting the numerical value of the result. Maxima is a full-featured open-source https://doi.org/10.3390/ CAS: the software can serve as a calculator, provide analytical expressions, and perform math9121317 symbolic manipulations.
    [Show full text]
  • Floating Point CSE410, Winter 2017
    L07: Floating Point CSE410, Winter 2017 Floating Point CSE 410 Winter 2017 Instructor: Teaching Assistants: Justin Hsia Kathryn Chan, Kevin Bi, Ryan Wong, Waylon Huang, Xinyu Sui L07: Floating Point CSE410, Winter 2017 Administrivia Lab 1 due next Thursday (1/26) Homework 2 released today, due 1/31 Lab 0 scores available on Canvas 2 L07: Floating Point CSE410, Winter 2017 Unsigned Multiplication in C u ••• Operands: * bits v ••• True Product: u · v ••• ••• bits Discard bits: UMultw(u , v) ••• bits Standard Multiplication Function . Ignores high order bits Implements Modular Arithmetic w . UMultw(u , v)= u ∙ v mod 2 3 L07: Floating Point CSE410, Winter 2017 Multiplication with shift and add Operation u<<k gives u*2k . Both signed and unsigned u ••• Operands: bits k * 2k 0 ••• 0 1 0 ••• 0 0 True Product: bits u · 2k ••• 0 ••• 0 0 k Discard bits: bits UMultw(u , 2 ) ••• 0 ••• 0 0 k TMultw(u , 2 ) Examples: . u<<3 == u * 8 . u<<5 - u<<3 == u * 24 . Most machines shift and add faster than multiply • Compiler generates this code automatically 4 L07: Floating Point CSE410, Winter 2017 Number Representation Revisited What can we represent in one word? . Signed and Unsigned Integers . Characters (ASCII) . Addresses How do we encode the following: . Real numbers (e.g. 3.14159) . Very large numbers (e.g. 6.02×1023) Floating . Very small numbers (e.g. 6.626×10‐34) Point . Special numbers (e.g. ∞, NaN) 5 L07: Floating Point CSE410, Winter 2017 Floating Point Topics Fractional binary numbers IEEE floating‐point standard Floating‐point operations and rounding Floating‐point in C There are many more details that we won’t cover .
    [Show full text]