Outline. Midterm Review. Declaring Variables. Main Variable Data Types. Symbolic Constants. Arithmetic Operators. Midterm Review March 24, 2014

Similar documents
Programming in Fortran 90 : 2017/2018

Programming Assignment Six. Semester Calendar. 1D Excel Worksheet Arrays. Review VBA Arrays from Excel. Programming Assignment Six May 2, 2017

Solutions to Programming Assignment Five Interpolation and Numerical Differentiation

Exercises (Part 4) Introduction to R UCLA/CCPR. John Fox, February 2005

Agenda & Reading. Simple If. Decision-Making Statements. COMPSCI 280 S1C Applications Programming. Programming Fundamentals

Brave New World Pseudocode Reference

Mathematics 256 a course in differential equations for engineering students

Parallelism for Nested Loops with Non-uniform and Flow Dependences

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following.

Analysis of Continuous Beams in General

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

Subspace clustering. Clustering. Fundamental to all clustering techniques is the choice of distance measure between data points;

An Application of the Dulmage-Mendelsohn Decomposition to Sparse Null Space Bases of Full Row Rank Matrices

Parallel Numerics. 1 Preconditioning & Iterative Solvers (From 2016)

Lecture 4: Principal components

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1)

Content Based Image Retrieval Using 2-D Discrete Wavelet with Texture Feature with Different Classifiers

Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids)

Sorting and Algorithm Analysis

News. Recap: While Loop Example. Reading. Recap: Do Loop Example. Recap: For Loop Example

Hermite Splines in Lie Groups as Products of Geodesics

CMPS 10 Introduction to Computer Science Lecture Notes

AMath 483/583 Lecture 21 May 13, Notes: Notes: Jacobi iteration. Notes: Jacobi with OpenMP coarse grain

Sorting Review. Sorting. Comparison Sorting. CSE 680 Prof. Roger Crawfis. Assumptions

Machine Learning 9. week

CS 534: Computer Vision Model Fitting

CSCI 104 Sorting Algorithms. Mark Redekopp David Kempe

2x x l. Module 3: Element Properties Lecture 4: Lagrange and Serendipity Elements

NUMERICAL SOLVING OPTIMAL CONTROL PROBLEMS BY THE METHOD OF VARIATIONS

NAG Fortran Library Chapter Introduction. G10 Smoothing in Statistics

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

Midterms Save the Dates!

Lecture #15 Lecture Notes

Polyhedral Compilation Foundations

A Binarization Algorithm specialized on Document Images and Photos

SENSITIVITY ANALYSIS IN LINEAR PROGRAMMING USING A CALCULATOR

S1 Note. Basis functions.

A MOVING MESH APPROACH FOR SIMULATION BUDGET ALLOCATION ON CONTINUOUS DOMAINS

MATHEMATICS FORM ONE SCHEME OF WORK 2004

Conditional Speculative Decimal Addition*

R s s f. m y s. SPH3UW Unit 7.3 Spherical Concave Mirrors Page 1 of 12. Notes

Lecture 5: Multilayer Perceptrons

Multiple optimum values

The Codesign Challenge

Smoothing Spline ANOVA for variable screening

Sequential search. Building Java Programs Chapter 13. Sequential search. Sequential search

AP PHYSICS B 2008 SCORING GUIDELINES

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6)

Lecture 5: Probability Distributions. Random Variables

Kent State University CS 4/ Design and Analysis of Algorithms. Dept. of Math & Computer Science LECT-16. Dynamic Programming

Today s Outline. Sorting: The Big Picture. Why Sort? Selection Sort: Idea. Insertion Sort: Idea. Sorting Chapter 7 in Weiss.

Oracle Database: SQL and PL/SQL Fundamentals Certification Course

Kinematics of pantograph masts

Problem Definitions and Evaluation Criteria for Computational Expensive Optimization

Biostatistics 615/815

Radial Basis Functions

Lobachevsky State University of Nizhni Novgorod. Polyhedron. Quick Start Guide

Course Introduction. Algorithm 8/31/2017. COSC 320 Advanced Data Structures and Algorithms. COSC 320 Advanced Data Structures and Algorithms

Array transposition in CUDA shared memory

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision

Life Tables (Times) Summary. Sample StatFolio: lifetable times.sgp

Classification / Regression Support Vector Machines

Intro. Iterators. 1. Access

A New Approach For the Ranking of Fuzzy Sets With Different Heights

Loop Transformations, Dependences, and Parallelization

Support Vector Machines

CSE 326: Data Structures Quicksort Comparison Sorting Bound

9. BASIC programming: Control and Repetition

Outline. Third Programming Project Two-Dimensional Arrays. Files You Can Download. Exercise 8 Linear Regression. General Regression

Sorting. Sorting. Why Sort? Consistent Ordering

Parallel matrix-vector multiplication

Insertion Sort. Divide and Conquer Sorting. Divide and Conquer. Mergesort. Mergesort Example. Auxiliary Array

Review of approximation techniques

Solitary and Traveling Wave Solutions to a Model. of Long Range Diffusion Involving Flux with. Stability Analysis

3D vector computer graphics

Proper Choice of Data Used for the Estimation of Datum Transformation Parameters

Improving Low Density Parity Check Codes Over the Erasure Channel. The Nelder Mead Downhill Simplex Method. Scott Stransky

LESSON 15: BODE PLOTS OF TRANSFER FUNCTIONS

Sorting: The Big Picture. The steps of QuickSort. QuickSort Example. QuickSort Example. QuickSort Example. Recursive Quicksort

Wishing you all a Total Quality New Year!

Inverse Kinematics (part 2) CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Spring 2016

USING GRAPHING SKILLS

Support Vector Machines

CS240: Programming in C. Lecture 12: Polymorphic Sorting

High level vs Low Level. What is a Computer Program? What does gcc do for you? Program = Instructions + Data. Basic Computer Organization

ON SOME ENTERTAINING APPLICATIONS OF THE CONCEPT OF SET IN COMPUTER SCIENCE COURSE

Parameter estimation for incomplete bivariate longitudinal data in clinical trials

Steps for Computing the Dissimilarity, Entropy, Herfindahl-Hirschman and. Accessibility (Gravity with Competition) Indices

Assembler. Shimon Schocken. Spring Elements of Computing Systems 1 Assembler (Ch. 6) Compiler. abstract interface.

On Some Entertaining Applications of the Concept of Set in Computer Science Course

Performance Evaluation of Information Retrieval Systems

Reading. 14. Subdivision curves. Recommended:

NGPM -- A NSGA-II Program in Matlab

A DATA ANALYSIS CODE FOR MCNP MESH AND STANDARD TALLIES

Cluster Analysis of Electrical Behavior

Hierarchical clustering for gene expression data analysis

Gaussian elimination. System of Linear Equations. Gaussian elimination. System of Linear Equations

An Optimal Algorithm for Prufer Codes *

APPLICATION OF MULTIVARIATE LOSS FUNCTION FOR ASSESSMENT OF THE QUALITY OF TECHNOLOGICAL PROCESS MANAGEMENT

Simulation: Solving Dynamic Models ABE 5646 Week 11 Chapter 2, Spring 2010

Transcription:

Mdterm Revew March 4, 4 Mdterm Revew Larry Caretto Mechancal Engneerng 9 Numercal Analyss of Engneerng Systems March 4, 4 Outlne VBA and MATLAB codng Varable types Control structures (Loopng and Choce) Arrays, Functons and Subs Roots of Equatons General approach and two examples Matrx bascs and soluton by Gaussan elmnaton Numercal dfferentaton/interpolaton Man Varable Data Types Common VBA Varable types Data Type Memory Sze Range Boolean bytes TRUE (non-zero) or FALSE () Integer bytes -,678 to,767 Long (nteger) 4 bytes -,47,48,648 to,47,48,647 Sngle 4 bytes (+/-).498E-45 to.48e8 Double 8 bytes (+/-) 4.94656458447E-4 to.79769486e8 Strng (varable-length) bytes + length to about bllon characters Date 8 bytes Date and tme of day Varant 6 bytes (more for strngs) Holds any data type (Default type) MATLAB uses double data type for numercal values and has strng data type All MATLAB varables can be complex arrays; no varable declaraton s requred Declarng Varables VBA uses the followng syntax Dm x As Double Dm k As Long For loop ndex Dm s As Strng, d as Date Dm y as Double, z As Double Do not use the followng syntax n whch x and y are type varant: Dm x, y, z As Double Declaratons not requred n MATLAB 4 Arthmetc Operators Operators for both VBA and MATLAB Exponentaton ^, Unary mnus (E.g. x), Multply/Dvde * / Addton/Subtracton + Both use parentheses to overrule normal rules of precedence MATLAB operators * / and ^ apply to arrays, but there are also term-by-term operators:.*./ and.^ MATLAB: A/B => AB - and A\B = A - B 5 Symbolc Constants Useful way to program tems that are constant or not expected to change often Syntax: Const PI as Double =.4596558979 A const cannot be assgned a value n any other statement Not avalable n MATLAB 6 ME 9 Numercal Analyss of Engneerng Systems

Mdterm Revew March 4, 4 Relatonal/Logcal Operators Program logc requres choces based on expressons that are true or false Relatonal operators compare other varables and have true or false results MATLAB and VBA use <, <=, =, >, >= Not equal s <> n VBA ~= n MATLAB VBA: Not, And, Or; MATLAB: ~, &&, MATLAB array comparsons return arrays of (true) and (false) and use ~ & 7 If Else If n VBA If <condton> Then <Statements done f condton s true> ElseIf <condton> Then <Statements done f condton s true> ElseIf <condton> Then <Statements done f condton s true> <May be other condtons> Else <Statements done f all condtons false> End If <Execute here after any statements done> 8 If Else If n MATLAB f <condton> <Statements done f condton s true> elsef <condton> <Statements done f condton s true> elsef <condton> <Statements done f condton s true> <May be other condtons> else <Statements done f all condtons false> end <Execute here after any statements done> 9 If Else If Explaned If any condton s true, the statements followng the If or ElseIf are executed Once those statements are executed controls to the frst statement after the End If Statements for only the frst true condton are executed The Else block s optonal If no condtons are true those statements are executed If <condton> The <Statements done ElseIf <condton> <Statements done ElseIf <condton> <Statements done <May be other cond Else <Statements done End If <Execute here after Loopng Count control loop repeats code a fxed number of tmes Condtonal loopng repeats whle a condton s true or untl a condton s false Both types of loops may be nested May use statements (VBA Ext For or Ext Do; MATLAB break) to ext loop before normal ext VBA Count Controlled Loop For <counter> = <start> to <end> <statements> If Step not specfed, Next <counter> <ncrement> = For <counter> = <start> to <end> _ Step <ncrement> <statements> Next <counter> Statements n loop repeated ntmes = Int((<end> <start>) /<ncrement>) + Loop not executed f ntmes <= ME 9 Numercal Analyss of Engneerng Systems

Mdterm Revew March 4, 4 MATLAB Count Controlled Loop for <counter> = <array> <statements> end Array may be set of values, e.g. for T = [ 7 6] Can use array defnton lke VBA for loop for <counter> = <start>:<ncrement>:<end> Statements n loop repeated for each element n array Note ablty to specfy non-unform array ncrement VBA Condtonal Loop <cond> s a condton (can be true or false) are statements executed n the loop (whch can change the condton) Do f <cond> _ Then Ext Do Loop Do Whle <cond> Loop Do Loop Whle <cond> Do Untl <cond> Loop Do Loop Untl <cond> Note tests before or after loop 4 MATLAB Condtonal Loop Only one loop, a whle loop, wth the followng structure whle <condton> <statements> end Example (compute machne epslon) eps = whle + eps ~= eps = eps / end eps = eps * 5 Arrays Arrays can be vsualzed as data on an expermental varable Could descrbe pressure data ponts mathematcally as P, P, etc. In programmng languages we can represent data ponts as P(), P(), etc. We call the numbers (,, etc.) ndces or subscrpts We can use constants or varables for the subscrpts: P(4), P(k), where k has a value 6 V() Two-dmensonal Arrays Consder an experment where you vary the current over sx levels, the voltage over four levels and measure the effcency, e, of an electromechancal devce. The data for each combnaton of current and voltage can be represented as shown below V() V() V(4) I() I() I() I(4) I(5) I(6) e(,) e(,) e(,) e(,4) e(,5) e(,6) e(,) e(,) e(,) e(,4) e(,5) e(,6) e(,) e(,) e(,) e(,4) e(,5) e(,6) e(4,) e(4,) e(4,) e(4,4) e(4,5) e(4,6) 7 Dmensonng Arrays n VBA Can declare arrays as follows Dm I( to 6) as double Dm V( to 4) as double Dm e( to 4, to 6) as double Sze below depends on Opton Base Dm I(6) as double Array Dm V(4) as double dmensonng not requred n Dm e(4, 6) as double MATLAB 8 ME 9 Numercal Analyss of Engneerng Systems

Mdterm Revew March 4, 4 Usng Arrays n VBA VBA array components are referenced by ther subscrpts Ths s often done n a for loop PI = 4 * atn() For k = to x(k) = sn(k * PI / ) Next k In MATLAB use: t = :p/:p x = sn(t) x s an array wth components gvng sn(x) for x p, wth Dx = p/ Two-Dmensonal Arrays n VBA Use nested for loops Use example of exstng data on current and voltages stored n arrays For k = to 4 For j = to 6 Power(k,j) = current(j) * voltage(k) Next j Next k 9 MATLAB Arrays Enter arrays as x = [ ; 4 5 6 Elements n one row separated by spaces Semcolon ndcates new row Subarrays z = x(r:r,c:c); transpose x Array formula operators: +, -, *, /,\,^ gve matrx results (A/B = AB -, A\B = A - B) Term-by-term operatons wth +, -,.*,./,.^ Buld larger arrays from smaller arrays usng same approach enterng ntal array VBA Strngs Consder only varable length Use Dm str as Strng to dmenson strng Use & or + as concatenaton operator to jon two strngs Len(str) gves length of strng Left, Rght, and Md gve substrngs n same manner as worksheet functons InStr functon searches for substrngs Strng constant s = strng MATLAB Strngs Use sngle quotes for strng constants Settng s = strng makes s a strng varable wth the value strng No declaraton requred Concatenate strngs by placng them n an array of strngs s = [ Ths strng has characters ] result: s = Ths strng has characters VBA Functons The header has the followng form Functon <name> ( <arguments> ) As <type> <name> s the name of the functon Must set name to some value n functon code <type> s the data type for the functon <arguments> may be blank or have one or more entres of the form <varable> As <type> <varable> s a varable used n the functon <type> s the data type for that varable Separate multple entres n the lst by commas Arguments provde nput data to functon 4 ME 9 Numercal Analyss of Engneerng Systems 4

Mdterm Revew March 4, 4 Wrtng Your VBA Functon The functon has the followng form Functon <name> ( <arguments> ) As <type> <code to do computatons> <name> = <value from computatons> End Functon Example functon Functon vcyl ( R as Double, H as Double ) As _ Double vcyl = 4 * atn() * R^ * H End Functon Usng Your VBA Functon Use by cell entres n worksheet =vcyl( B, B) =vcyl(, ) =vcyl( radusname, heghtname) Call from other VBA procedures V = vcyl( radus, heght) cylvol = vcyl(, ) vcyls = * vcyl( rad, hgt) 5 6 MATLAB Functons The header has the followng form functon <return> = <name> ( <arguments> ) <return> s a one varable or row array of varables returned by the functon <name> s the name of the functon <arguments> may be blank or have one or more varable names separated by commas Arguments provde nput data to functon Varables n the <return> lst must be assgned a value n the functon 7 MATLAB Trajectory Functon functon [x, y] = traj(v, theta, N) %Computes frctonless trajectory Use fle %Uses SI unts (meters, seconds) names the %V s ntal speed n m/s same as the %theta s ntal angle n degrees functon %N s number of ponts computed g = 9.8665; %gravty n m/s^ names (e.g. tmax = * v * snd(theta) / g; traj.m) to t = :tmax/(n-):tmax; save x = v*cosd(theta) * t; functons y = v*snd(theta) * t - g * t.^ /; plot(x,y); end Operator.^ allows use of t as an array 8 Usng the Trajectory Functon Use only the functon name wll return value of frst argument, x, n default varable ans >> trajectory(, 45, ); Return x array only >>x = trajectory(, 45, ) Return x and y arrays >> [x,y] = trajectory(, 45, ) Roots of Equatons, f(x) = Plot of f (x) = x and f (x) = e x/ sn(4x) f(x) = x e x/ sn(4x) = Roots about x =, x =.8, x =.6, etc. Plot shows that ths equaton has nfnte number of roots 9 ME 9 Numercal Analyss of Engneerng Systems 5

Mdterm Revew March 4, 4 Iteraton Solutons In teraton we make one (or more) ntal guesses for x and compute f(x) x (m) or x m s value of x at teraton m f (m) or f m = f(x m ) s value of f(x) at x = x m Unless we are extremely lucky we wll not fnd f(x) = for ntal guesses Use recent value(s) of f(x) to estmate a value of x that gets us closer to the soluton x* at whch f = Convergence Crtera x + x e + e x + OR f + e combnes tests on x and f Useful when df/dx >> or df/dx << n the regon of the soluton Although we are tryng to solve for f =, we are really nterested n fndng the value of x Error tests on x are usually more mportant Relatve error test s more general Secant Method Operaton Algorthm: Make ntal guesses x and x Compute f = f(x ) and f = f(x ) Repeat x + = x f [(x x - ) / (f f - )] Untl convergence crteron s met Algorthm does not requre ntal guesses that bracket root, but bad ntal guesses may not converge quckly or at all Secant Method Example f(x) = e x x Intal guesses x = and x = f = f(x ) = f() = e = f = f(x ) = f() = e =.878 x = x f x x f f =.878 x =.9 f = f(x ) = e.9.99 =.656 x = x f x x f f =.9.656 x =.99; f =.5 Root s.469658.878.9.65.88 4 Newton s Method Operaton Algorthm: Make ntal guess x Compute f = f(x ) and f (x ) = df/dx x=x Repeat x + = x f / f (x ) Untl convergence crteron s met Algorthm requres only one ntal guess A bad ntal guesses may not converge quckly or at all or converge to wrong root 5 Newton s Method Example f(x) = e x x f (x) = e x Intal guess x = (x = gves f = ) f = f(x ) = f() = e =.878 f (x) = e =.788 x = x f f (x ) =.878.788 =.695 f x = e.65.695 =.866 f x = e.65 =.569 x = x f.866 =.695 =.464 f (x ).569 Fnd x 4 =.4696, f() = 8.x -8 6 ME 9 Numercal Analyss of Engneerng Systems 6

Mdterm Revew March 4, 4 Matrx Bascs Matrx s array wth n rows and m columns A = B f same sze and a j = b j for all and j Add or subtract matrces C = A B only vald f A, B, and C have the same sze (rows and columns) Components of C, c j = a j b j Multplcaton by a scalar: C = xa C and A have the same sze (rows and columns) Components of C, c j = xa j For scalar dvson, C = A/x, c j = a j /x 7 Null () and Unt (I) Matrces For any matrx, A, A + = + A = A; IA = AI = A and A = A = The unt (or dentty) matrx s a square matrx; the null matrx, whch need not be square, s sometmes wrtten (nxm) I 8 Dagonal Matrx and Transpose Dagonal matrx, D, has nonzero terms only on dagonal Transpose of A, denoted as A T swtches rows and columns 6 A 4 d D T d d A 6 d n 4 9 General Matrx Multplcaton For matrx multplcaton, C = AB p A has n rows and p columns cj bkakj B has p rows and m columns k C has n rows and m columns (, n; j, m ) Example A 4 () () 6(6) AB 4() () (6) 4 6 B 6 (4) () 6() 7 4(4) () () 6 4 Inverse of a Matrx For a square matrx, A, an nverse matrx, A - may exst such that AA - = A - A = I For the algebrac equaton ax = b, x = a - b For the matrx equaton Ax = b, x = A - b Just as x = a - b s not vald f a =, x = A - b s not vald f A - does not exst A - does not exst f DetA = The nverse and the determnant are mportant concepts n analyss of lnear systems, but are not used n computatonal work 4 From Equatons to Ax = b Usual form for N = equatons x + 7y z = 8 x 4y + z = - 8x + 6y z = 4 A x = Ax = b 7 x x 7x x 8 4 x x 4x x 8 6 x 8 6 4 x x x An equaton s a row n the Ax = b format 4 ME 9 Numercal Analyss of Engneerng Systems 7

Mdterm Revew March 4, 4 Gaussan Elmnaton Solve the set x 4x 6x 4 ( ) of equatons x 9 ( ) on the rght x x 7x 8 4 ( ) x x Subtract / tmes () from equaton () and 7/ tmes () from () x ( 4) x 9 ( 6) x ( 4) 7 7 7 7 7 x ( 4) x 8 ( 6) x 4 ( 4) Gaussan Elmnaton II Result from frst set of operatons Subtract 7/(-4) tmes () from () Fnal uppertrangular form x 4x 6x 4 x 4x x 8 x 7x 99x 4 44 Unnecessary computer operatons 7 x 7 ( 4) x 99 4 7 7 ( ) ( 8) 4 4 x 4x 6x 4 x 4x x 8 57 x x x 57 Fnal uppertrangular form Solve thrd equaton for x Back Substtuton x 4x 6x 4 4x x 8 57 x 57 57 x 57 Solve second 8 x 8 x equaton for x 4 4 Solve frst equaton for x 4x 6x 4 4 6x x 4 45 General Gaussan Loop over all rows from to N to be used as the pvot row For each pvot row, loop over all rows from pvot + to N For each row loop over all columns from pvot+ to N + nbcols (work wth augmented matrx [A b] a row, pvot a row, column row, column apvot, column apvot, pvot n Back substtuton formula for = n, n-,, : a b x j j a a x 46 j Solutons for Ax = b For a set of m equatons n n unknowns If Rank(A) = Rank([A b]) = n, there s a unque soluton If Rank(A) = Rank([A b]) < n, there are an nfnte number of solutons If Rank(A) Rank([A b]) there are no solutons Use Gaussan elmnaton to fnd Rank as number of nonzero rows x 4x x 7x x x 4x x x x 6x 9x 8x x 4x x x x Three Examples 9x 6x 6x 5 5 6x 9x 6x 9 5 8 x 4x 9x 5.5x 5 5.5 47 48 x x 4x x x 4x x 6x 9x 6x 9x 6x 5 5 x x 7 x x 8 8 x.5 4.5 x No soluton ME 9 Numercal Analyss of Engneerng Systems 8

Mdterm Revew March 4, 4 Frst Example Rank Second Example Rank Orgnal Rowechelon form A 7 4 6 9 8 A b 7 4 6 A 9 A b 5.5 4 4 Here we see that rank(a) = rank([a b]) = number of unknowns = so we have a unque soluton 6 9 5 8 6 9 5 5.5 5.5 49 Orgnal Rowechelon form A 4 6 9 6 A b 4 6 A 9 A b 4 4 6 9 5 6 9 6 9 5 rank(a) = rank([a b]) = whch s less than the number of unknowns () so we have an nfnte number of solutons 5 Orgnal Rowechelon form Thrd Example Rank A 4 6 9 6 A b 4 6 A 9 A b 4 4 Here, rank(a) = rank([a b]) = ; therefore we have no solutons 6 9 5 6 8 6 9 5 5 Numercal Dfferentaton Formulas have followng propertes Type of dervatve (frst, second, thrd, etc.) Locaton of ponts used n the dervatve, relatve to the pont of the dervatve (forward dfference, backward dfference, central dfference) Order of the error: O(h n ) s an n th order error (truncaton error proportonal to h n ) Roundoff error occurs when h s so small that sgnfcant fgures are lost 5 ' Some Dervatve Expressons f f f ' Oh h f f f h O h Note order of dervatve, order of error, and drecton (forward vs. backward) ' ' f f f h f f ' f f 4 f h 4 f h O h f f '' f f f f h O h O h O h O(h n ) for nformaton only. Not used n calculatons. 5 More Dervatve Expressons f = f 5f + 4f f h + O h f = f + + 8f + 8f + f + O h 4 h f = f + 6f f + 6f + + f + h + O h 4 What s order of dervatve, order of error, and drecton (central, forward or backward dfference ) of expresson? Is sum of coeffcents always zero? 54 ME 9 Numercal Analyss of Engneerng Systems 9

Mdterm Revew March 4, 4 Polynomal Interpolaton Ft n th order polynomal, p(x), to n + data ponts, (x, y ) to (x n, y n ) Can start at any data pont n set Select ponts for nterpolaton that are closest to the value to be nterpolated Basc dea s that polynomal wll ft each data pont exactly: p(x ) = y Example s Newton polynomal a + a (x x ) + a (x x )(x x ) + a k coeffcents from dvded-dfference table 55 Newton Polynomals from x start p (x) = a and p (x) = a + a (x x start ) p (x) = a + a (x x start ) + a (x x start ) (x x start+ ) p (x) = a + a (x x start ) + a (x x start ) (x x start+ ) + a (x x start ) (x x start+ )(x x start+ ) a = y start, a = F start = (y start+ y start ) / (x start+ x start ). a = S start = (F start+ n m pnx amx xstartk pnx pn x an x xstartk m k n k 56 x = Sample Dvded Dfference Table y = a Follow same a y y k pattern for F a other startng ponts x x y = F F S a x y y x F S S T a x x x x F F T T 5 y =5 S R x x x y y S S F T a x 4 x x F F 5 y = S x Dvded dfference y4 y table gves polynomal F x coeffcents (next 9 y 4 =79 page) 57 Dvded Dfference Table for p(x = ) X = y = 5 6 y y F F 5 5 x x F F y = a S 5 7 4 x x F y y S 5 S 5 5 5 F a T x x x x F F 5 y =5 S T T x a R x x y y S S 4 x F T x x x F F 5 y = S x y4 y F 4 6 x x 5 5 5 8 7 S 9 y 4 =79 5 4 5 5 54 58 Quadratc Polynomal Usual form for ntal pont at x = x p (x) = a + a (x x ) + a (x x )(x x ) Here we start at x start = x p (x) = a + a (x x ) + a (x x )(x x ) Usng data from prevous chart gves 6 7 px x x x 5 5 Ths gves p(x k ) = y k for x k =, 5, and 5 Interpolated value for x = s 89 59 Mdterm Exam Closed book (code sheet on exam shows basc VBA and MATLAB structures) Problems lke those on quzzes Interpretng VBA or MATLAB code Wrtng smple VBA or MATLAB code Usng a gven algorthm to solve f(x) = Smple matrx operatons (equalty, addton, subtracton, multplcaton, transpose) Smple Gaussan elmnaton (4 x 4 system) Recognze unque, zero, or nfnte solutons Numercal dfferentaton and nterpolaton 6 ME 9 Numercal Analyss of Engneerng Systems

Mdterm Revew March 4, 4 Sxth Quz Results Number of students: Maxmum Possble Score: 5 Average score: 8. Medan score:.5 Standard devaton: 6.7 Grade dstrbuton: 5 9 5 7 8 8 9 4 4 5 5 5 6 Sxth Quz Comments Choose data ponts n the regon of the x value to be nterpolated Denomnators of dvded dfference expressons are always Dx s Choose central-dfferences dervatve expressons f possble; use one-sded dfferences for boundares only To fnd the n th dervatve of y n a table of y vs. x, use y values n the numerator 6 Sxth Quz Comments II O(h n ) s for nformaton about order of error only, not part of calculaton For dervatves from a data table h = D(ndependent varable) Numerator values are dependent varable Here x s ndependent, y dependent Asked to fnd second dervatve of y Do not have to get entre dvdeddfference table, only the terms needed Look for type of polynomal requred 6 ME 9 Numercal Analyss of Engneerng Systems