ECE257 Numerical Methods and Scientific Computing Lecture 2 Programming and Software Parts adapted from MIT 12 010 Lecture Notes Thomas Herring Packages vs Programming Packages MATLAB Mathematica Maple Excel Packages do the work for you Most offer an interactive environment ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut MATLAB Software product from The MathWorks Inc Originally focused on matrix manipulations Interactive tool to do numerical functions symbolic computiations and visualization Commands can be saved into user scripts call and m file Graphics and Graphical user interfaces GUI are built into program ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut MATLAB ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut MATLAB Base product is extended with a variety of toolboxes Optimization Statistics Curve fitting Image Processing ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut MATLAB 3 2 Example Find roots of x 6x 72x 27 p 1 6 72 27 r roots p r 12 1229 5 7345 0 3884 ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut MATLAB Advantages Large library of functions to evaluate a wide variety of numerical problems Interactive tool allows immediate evaluation of results Disadvantages Expensive Not as fast as C C FORTRAN code ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Symbolic Computation Products include Mathematica and Maple These products attempt to do analytical solutions of equations instead of numerical methods You get an equation back as the answer rather than numbers ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Programming language concepts Interpreted Languages MATLAB Java BASIC VB Usually integrated with an interactive GUI Scripting based Many interpreted languages do not have types Allows quick evaluation of algorithms Ideal for debugging and one time analysis and in cases where high speed is not critical ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Programming language concepts Compiled Languages FORTRAN C C Source code is created with an editor as a plain text file Programs then needs to be compiled converted from source code to machine instructions with relative addresses and undefined external routines still needed The compiled routines called object modules need then to be linked with system libraries Faster execution than interpreted languages Static type checking ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Programming concepts Data representation Constants variables type declarations int x const g 9 8 integer type declaration constant Data organization and structures Arrays lists trees etc int matrix 10 10 2 d integer array struct linked list node struct node next node ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Programming concepts Mathematical formulas Assignment precedence rules x y 5 y x 4 Input Output Stdin Stdout files GUI printf Hello world outf x x ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Programming concepts Structured programming Set of rules that prescribe good programming style Single entry point and exit point to all control structures Modular programming Introduced by ALGOL and continued on by PASCAL C and their derivatives ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Structured programming Control structures Sequence Selection Repetition ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Algorithm expression Flowcharts Visual representation Useful in planning Pseudocode Simple representation of an algorithm Basic program constructs without being language specific ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Flowcharts From Numerical Methods for Engineers Chapra and Canale Copyright The McGraw Hill Companies Inc ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Control structures Sequence From Numerical Methods for Engineers Chapra and Canale Copyright The McGraw Hill Companies Inc ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Control structures Selection Branching IF THEN ELSE CASE ELSE From Numerical Methods for Engineers Chapra and Canale Copyright The McGraw Hill Companies Inc ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Control structures From Numerical Methods for Engineers Chapra and Canale Copyright The McGraw Hill Companies Inc ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Control structures From Numerical Methods for Engineers Chapra and Canale Copyright The McGraw Hill Companies Inc ECE 257 Numerical Methods and Scientific Computing Fall 2004 Lecture 1 John A Chandy Dept of Electrical and Computer Engineering University of Connecticut Control structures Repetition DOEXIT loops break loop Similar to C while loop DOFOR loop count
View Full Document