Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE 206 1 Review—Fortran. CSCE 206 2 Review—I/O Patterns: Read until a sentinel value is found Read n, then read n things Read until EOF encountered.

Similar presentations


Presentation on theme: "CSCE 206 1 Review—Fortran. CSCE 206 2 Review—I/O Patterns: Read until a sentinel value is found Read n, then read n things Read until EOF encountered."— Presentation transcript:

1 CSCE 206 1 Review—Fortran

2 CSCE 206 2 Review—I/O Patterns: Read until a sentinel value is found Read n, then read n things Read until EOF encountered Techniques: Unformatted reads (preferred) Formatted reads (deprecated) Unformatted writes (deprecated) Formatted writes (preferred)

3 CSCE 206 3 Conditional Execution IF (…) THEN … ELSE … END IF Keep it simple Follow rules of boolean logic Use Logical variables if necessary

4 CSCE 206 4 Loops DO n = begin,end,step END DO ………………………………………………….. DO IF(we’re done) THEN EXIT END IF … END DO

5 CSCE 206 5 Loops X = initial value DO n = begin,end,step update X END DO Works for finding min, max, Works for sum of values, product of values

6 CSCE 206 6 Loops DO IF(we’re done) THEN EXIT END IF … END DO Works for searching, indeterminate termination conditions

7 CSCE 206 7 Data Types and Variables Intrinsic logical, character, integer, real, complex Structures Static or dynamic allocation Call by reference, call by value INTENT keyword

8 CSCE 206 8 Subprograms and Scope of Variables Functions and subroutines Internal and external Variables are available to internal subprograms unless otherwise redefined Variables are not available to external subprograms

9 CSCE 206 9 Algorithms

10 CSCE 206 10 Pointers to Data Sorting with an index array Linked lists, queues, stacks Old fashioned way used arrays bad—more cumbersome? good—all the data can be read More modern way uses dynamic allocation bad—can’t necessarily find the data good—perhaps simpler

11 CSCE 206 11 Divide and Conquer Bisection is divide and conquer Split the problem in half Determine which half is relevant Inherently fast

12 CSCE 206 12 Algorithm Analysis f(n) = O(g(x)) means f(x) < C g(x) for some fixed constant C and “all large x” If f(x) is a polynomial, then it’s big O of the leading term Hierarchy log n n n log n n^2 …

13 CSCE 206 13 Numerical Algorithms

14 CSCE 206 14 Root Finding Bisection method more or less guaranteed to work but slow to converge Newton’s method generally fast in convergence but less predictable

15 CSCE 206 15 Approximation of Functions Forward (backward) difference approximations: Approximate derivatives with slopes from data points forward (backward) from an initial base point Central difference approximations: Approx with average forward and backward Both methods approx a function with a polynomial by approximating the derivatives using data points and then approximating the function with a Taylor series Lagrange interpolation: Create the exact polynomial passing through the data points.

16 CSCE 206 16 Approximation of Functions When the data is felt to be accurate, difference methods are appropriate. When the data is known to be inaccurate, a least squares approximation is used. Usually: Minimize the sums of the errors in the vertical (y) direction if we were to approx the function with a straight line If we have nonlinear data, do a transformation, then approximate with a straight line.

17 CSCE 206 17 Means, Variances, etc. Mean can be computed “online” Variance can be computed online, but is usually expressed as a computation that requires first computing the mean

18 CSCE 206 18 Random Numbers Monte Carlo computations Numerical integration Simulation of statistical events (traffic flow, particle interactions, etc.)

19 CSCE 206 19 Differential Equations Start from an initial condition (time zero, for example) Estimate rate of change numerically Proceed in the direction of that change for one time step Recalculate rates of changes repeat

20 CSCE 206 20 Sorting Bubble sort/insertion sort, O(n^2) time, but there are faster ways Sort data? Sort keys? Create an index array but don’t move the data itself?

21 CSCE 206 21 Matrix Operations Matrix multiplication Loops

22 CSCE 206 22 Gaussian Elimination The most basic of all direct linear system solvers Also not very stable or successful, and not very efficient Best done as vector-matrix multiplication either explicitly or implicitly

23 CSCE 206 23 Gauss-Seidel Iteration The most basic of all iterative linear system solvers Reasonably stable and successful, and reasonably efficient Can be done either sequentially (G-S) or in parallel (Jacobi iteration)

24 CSCE 206 24 The End


Download ppt "CSCE 206 1 Review—Fortran. CSCE 206 2 Review—I/O Patterns: Read until a sentinel value is found Read n, then read n things Read until EOF encountered."

Similar presentations


Ads by Google