Unformatted text preview:

1Numerical Computing9-2-20052Opening Discussion■What did we talk about last class?■Have you done anything on the code from last time?■What do you know about how we represent numbers on computers?3Pointers and References■Most programming languages give you a way to reference things indirectly. In C you can use pointers. In C++ you can use pointers or references.■A pointer is a memory location that stores the address of another memory location. We can “follow” or dereference the pointer with the *. Given an object, we can get the address of it with &. If we have a pointer to a structure we can use “->” instead of “(*_).”.■A reference in C++ must be initialized at creation and simply becomes another name for a given memory location.4Example■Let's do the Mandelbrot code using both pointers and references to demonstrate how this can work.5Matlab■We have Matlab installed on these machines. Why don't you go ahead and start up Matlab and we will do the rest of the day in it, even though what we are going to do could be done in C/C++.6Floating Point Numbers■Computers represent all numbers in binary (base 2). For fractional numbers we typically us a notation called floating point. This is very much like scientific notation using binary.■The standard for floating point is IEEE 754. This comes in both single and double precision. Both styles have one byte for the sign followed by bits for an exponent and a fractional part.■For single precision the exponent gets 8 bits (with a bias of 127) and the fraction/mantissa gets the remaining 23.■Double precision gets 11 for the exponent (1023 biased) and 52 for the fraction.■Both assume a leading 1.7What it means to you■The details of IEEE 754 don't matter to most people. What does matter is that these numbers are the “real” numbers from math.■Having limited precision means some properties, like associativity, don't always hold.■The real key is that not all numbers can be represented perfectly. This is similar to the fact that we can't represent numbers like 1/3rd in decimal with a finite number of digits.■Similarly, there are some types of operations that should be avoided.Don't subtract two numbers that differ by an amount much smaller than their magnitude.Don't divide by very small numbers.8Advantages of Tools■These rules of thumb are part of the reason many scientists will use tools like Matlab or existing libraries. Often these libraries will use special alternate formulas in situations where the “normal” one is poorly behaved.■It is often difficult enough just to get the math right without worrying too much about how the numerics will behave.9Minute Essay■Matlab has a built in constant called eps which is the smallest number such that 1+eps>1. Write a loop in C/C++ that would calculate eps.■Have a good extended weekend and remember to read chapters 4 and 5 from the Matlab book for next


View Full Document

TRINITY CSCI 2323 - Lecture Notes

Documents in this Course
Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?