Solutions to Programming Assignment Five Interpolation and Numerical Differentiation

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

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

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

Optimization Methods: Integer Programming Integer Linear Programming 1. Module 7 Lecture Notes 1. Integer Linear Programming

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

S1 Note. Basis functions.

AP PHYSICS B 2008 SCORING GUIDELINES

y and the total sum of

THE PHYSICS 23 LAB BOOK 23 Lab 03: Conservation of Linear Momentum

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

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

TN348: Openlab Module - Colocalization

Quality Improvement Algorithm for Tetrahedral Mesh Based on Optimal Delaunay Triangulation

NAG Fortran Library Chapter Introduction. G10 Smoothing in Statistics

Support Vector Machines

Merging Results by Using Predicted Retrieval Effectiveness

Mathematics 256 a course in differential equations for engineering students

Determination of Body Sway Area by Fourier Analysis of its Contour

Cubic Spline Interpolation for. Petroleum Engineering Data

Review of approximation techniques

LESSON 15: BODE PLOTS OF TRANSFER FUNCTIONS

Parallelism for Nested Loops with Non-uniform and Flow Dependences

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

Generating Fuzzy Term Sets for Software Project Attributes using and Real Coded Genetic Algorithms

Reading. 14. Subdivision curves. Recommended:

Programming in Fortran 90 : 2017/2018

Synthesizer 1.0. User s Guide. A Varying Coefficient Meta. nalytic Tool. Z. Krizan Employing Microsoft Excel 2007

Performance Evaluation of Information Retrieval Systems

On-line Scheduling Algorithm with Precedence Constraint in Embeded Real-time System

Lecture #15 Lecture Notes

Type-2 Fuzzy Non-uniform Rational B-spline Model with Type-2 Fuzzy Data

Introduction. Leslie Lamports Time, Clocks & the Ordering of Events in a Distributed System. Overview. Introduction Concepts: Time

3D vector computer graphics

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

Poly-energetic Reconstructions in X-ray CT Scanners

Feature Reduction and Selection

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

Analysis of Continuous Beams in General


Low training strength high capacity classifiers for accurate ensembles using Walsh Coefficients

Interpolation of the Irregular Curve Network of Ship Hull Form Using Subdivision Surfaces

Multicast Tree Rearrangement to Recover Node Failures. in Overlay Multicast Networks

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

Introduction to Geometrical Optics - a 2D ray tracing Excel model for spherical mirrors - Part 2

LOOP ANALYSIS. The second systematic technique to determine all currents and voltages in a circuit

ECONOMICS 452* -- Stata 11 Tutorial 6. Stata 11 Tutorial 6. TOPIC: Representing Multi-Category Categorical Variables with Dummy Variable Regressors

A Binarization Algorithm specialized on Document Images and Photos

A Newton-Type Method for Constrained Least-Squares Data-Fitting with Easy-to-Control Rational Curves

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

LS-TaSC Version 2.1. Willem Roux Livermore Software Technology Corporation, Livermore, CA, USA. Abstract

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

Pattern Classification of Back-Propagation Algorithm Using Exclusive Connecting Network

LECTURE NOTES Duality Theory, Sensitivity Analysis, and Parametric Programming

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

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.

Subdividing Barycentric Coordinates

Intra-Parametric Analysis of a Fuzzy MOLP

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

Research on action recognition method under mobile phone visual sensor Wang Wenbin 1, Chen Ketang 2, Chen Liangliang 3

An Accurate Evaluation of Integrals in Convex and Non convex Polygonal Domain by Twelve Node Quadrilateral Finite Element Method

6.854 Advanced Algorithms Petar Maymounkov Problem Set 11 (November 23, 2005) With: Benjamin Rossman, Oren Weimann, and Pouya Kheradpour

A Theory of Non-Deterministic Networks

Analysis of 3D Cracks in an Arbitrary Geometry with Weld Residual Stress

X- Chart Using ANOM Approach

Radial Basis Functions

Color Image Segmentation Based on Adaptive Local Thresholds

Correlative features for the classification of textural images

CS 534: Computer Vision Model Fitting

Comparative Study between different Eigenspace-based Approaches for Face Recognition

UNIT 2 : INEQUALITIES AND CONVEX SETS

NUMERICAL SOLVING OPTIMAL CONTROL PROBLEMS BY THE METHOD OF VARIATIONS

USING GRAPHING SKILLS

The Codesign Challenge

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

126 Int. J. Ad Hoc and Ubiquitous Computing, Vol. 1, No. 3, Djamel Djenouri*

A CLASS OF TRANSFORMED EFFICIENT RATIO ESTIMATORS OF FINITE POPULATION MEAN. Department of Statistics, Islamia College, Peshawar, Pakistan 2

Virtual Memory. Background. No. 10. Virtual Memory: concept. Logical Memory Space (review) Demand Paging(1) Virtual Memory

A Five-Point Subdivision Scheme with Two Parameters and a Four-Point Shape-Preserving Scheme

An Efficient Fault-Tolerant Multi-Bus Data Scheduling Algorithm Based on Replication and Deallocation

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision

Multiblock method for database generation in finite element programs

VISUAL SELECTION OF SURFACE FEATURES DURING THEIR GEOMETRIC SIMULATION WITH THE HELP OF COMPUTER TECHNOLOGIES

Topology Design using LS-TaSC Version 2 and LS-DYNA

Analysis of Non-coherent Fault Trees Using Ternary Decision Diagrams

Cluster Analysis of Electrical Behavior

S.P.H. : A SOLUTION TO AVOID USING EROSION CRITERION?

Intro. Iterators. 1. Access

Computer models of motion: Iterative calculations

Classifier Selection Based on Data Complexity Measures *

What is Object Detection? Face Detection using AdaBoost. Detection as Classification. Principle of Boosting (Schapire 90)

Kinematics of pantograph masts

A MOVING MESH APPROACH FOR SIMULATION BUDGET ALLOCATION ON CONTINUOUS DOMAINS

LU Decomposition Method Jamie Trahan, Autar Kaw, Kevin Martin University of South Florida United States of America

Solving two-person zero-sum game by Matlab

ECONOMICS 452* -- Stata 12 Tutorial 6. Stata 12 Tutorial 6. TOPIC: Representing Multi-Category Categorical Variables with Dummy Variable Regressors

THE THEORY OF REGIONALIZED VARIABLES

SPH simulation for seismic behavior of earth structures

AVO Modeling of Monochromatic Spherical Waves: Comparison to Band-Limited Waves

SENSITIVITY ANALYSIS IN LINEAR PROGRAMMING USING A CALCULATOR

Research Article Quasi-Bézier Curves with Shape Parameters

Transcription:

College of Engneerng and Coputer Scence Mechancal Engneerng Departent Mechancal Engneerng 309 Nuercal Analyss of Engneerng Systes Sprng 04 Nuber: 537 Instructor: Larry Caretto Solutons to Prograng Assgnent Fve Interpolaton and Nuercal Dfferentaton Unless stated otherwse use the standard data set below for all nterpolaton probles n ths assgnent. x 805 85 845 865 885 905 95 945 965 985 y 0.70 0.763 0.907.336.69.598 0.96 0.67 0.65 0.606. Usng MATLAB a. Revew the help fle for the MATLAB splne functon. Copy the standard data set above nto MATLAB and plot a curve showng a coparson of the data and a cubc splne ft. (Obtan plot data for x =.) Copare ths plot to the one n the course notes. Dscuss ths coparson and lst the opton that you used n MATLAB for handlng the endponts. Accordng to the MATLAB docuentaton usng the splne functon n the for splne(x,y,xx) where x and y are equal szed vectors results n the not-a-knot end condton. Ths condton was derved n class n two ways () by assung that the second dervatve s lnear near the endpont and () by assung contnuty of the thrd dervatve at the second and next-to-last knots. Other end condtons are possble as descrbed n the help secton. MATLAB also has an optonal Curve-Fttng toolbox, that contans a splnetool functon, whch allows dfferent end condtons. For a dscusson of splne end condtons, see the followng webstes for ore nforaton about MATLAB curve fttng: http://www.athworks.co/atlabcentral/newsreader/vew_thread/7988. See http://www.athworks.co/help/toolbox/curveft/splnetool.htl for nforaton about splnetool. b. Revew the help fle for the MATLAB functon polyft. Obtan a 9 th order polynoal to ft the sae data used for the splne ft. Use the transfored x varable to reduce error as descrbed n the help fle for polyft. Prepare a plot that copares the nterpolated results wth the orgnal data.. (Obtan plot data for x =.) Dscuss any dfference between your results and those n the course notes. The MATLAB code for both parts a and b s shown below. >> %Intal code that apples to both splne and polynoal fts >> forat copact >> %Get x and y data for nterpolaton >> x = [805 85 845 865 885 905 95 945 965 985]; >> y = [0.70 0.763 0.907.336.69.598 0.96 0.67 0.65 0.606]; >> %Get an xplot array to plot nterpolated functons >> xplot = 800:000; >> %Get ysplne to plot as y values ftted to splne nterpolaton >> ysplne = splne(x,y,xplot); >> %Get scaled coeffcents for Newton polynoal >> [p S u]=polyft(x,y,9); >> %Get y data to plot usng polyval arguents to scale xplot >> ynewton = polyval(p,xplot,s,u); >> plot(x,y,'o',xplot,ysplne,'b',xplot,ynewton,'r') >> axs([800 000-5]) >> legend('data', 'splne', 'newton') Jacaranda Hall 334 Mal Code Phone: N/A Eal: lcaretto@csun.edu 8348 Fax: 88.677.706

Soluton to prograng assgnent fve ME309, L. S. Caretto, Sprng 04 Page >> grd %places grd on plot >> ttle('coparson of Interpolaton Approaches') >> xlabel('x') >> ylabel('y') The resultng MATLAB plot s shown n Fgure, below. The plot appears to be alost the sae as the cubc splne and Newton polynoal plots shown n the class notes. The splne plot gves a sooth ft to the data whle the 9 th -order Newton polynoal has unrealstc overshoots and undershoots of the data range. Near the axu and nu values of the x data used for the nterpolaton the cubc splne appears to gve reasonable extrapolaton results, whle the Newton polynoal ncreases draatcally below the frst x data pont and decreases just as draatcally as the value of x goes beyond the fnal data pont used for the nterpolaton. Fgure Copy of MATLAB plot. Usng EXCEL VBA The results fro parts and 3 are suarzed below. Download the workbook pa5soln.xls to see all the cell forulas and VBA code for both these parts. a. Wrte a VBA functon that allows users to select x and y data fro a table n an Excel worksheet that they want to use as an nterpolaton table and, n the sae functon select another x value (not n the nterpolaton table) for whch they want an nterpolated value. You can assue that the nput x and y data for the nterpolaton wll be data ranges of or ore cells each; you can also assue that these cells wll be n rows or n coluns. The nuber of cells the user selects wll deterne the order of the polynoal. Your functon should ensure that the user has selected the sae nuber of cells for both the x and the y data. Apply your VBA code to obtan nterpolaton results for x = 853 and 96 usng lnear, quadratc and cubc polynoals that properly select the correct nput data to place these

Soluton to prograng assgnent fve ME309, L. S. Caretto, Sprng 04 Page 3 x values near the center of the range for the nterpolaton data. Dscuss the dfferences n your results for each nterpolated x value. The results are shown n the table below. Ths table s taken fro the workbook, pa5soln.xls; the VBA code s also n ths workbook. The cell forula used to deterne these results has the followng for: newton(<xrange>, <yrange>, <xpont>). In ths forula <xrange> s a set of n colun cells gvng the x data for the nterpolaton forula; <yrange> s the set of n colun cells for the y data that corresponds to the x data selected prevously; <xpont> s a sngle value of x to whch the nterpolaton forula (deterned by the data n <xrange> and <yrange>) wll be appled. The order of the nterpolaton forula s deterned by nuber of cells selected by the user. Selectng n cells gves an nterpolaton polynoal of order n. Users should select data that places the value of <xpont> n the ddle of the range used for the nterpolaton data. If the uses wants a polynoal of an odd order (, 3, 5, ) she wll have to select an even nuber of data ponts. These should be splt so that <xrange> (and the correspondng <yrange> contan the sae nuber of ponts on each sde of <xpont>. If the polynoal has an even order, the selecton s ore dffcult because there wll be ore data ponts on one sde of <xpont> than on the other. In ths case the user should frst consder an even nuber of ponts rangng fro <xrange()> to <xrange(n)>, wth the nae nuber of ponts on each sde of <xpont>. Ths user should then dscard the data pont that has the hgher value of <xpont> <xrange()> or <xpont> <xrange(n)>. Ths crteron was used to select the data ponts for the results n the Quadratc colun n the table below. In that colun, the data ponts at x = 85, 845, and 865 were used to nterpolate the value at x = 853 and the values at x = 945, 965, and 985 were used to nterpolate the value at x = 96. In the Quadratc, the choces for the frst nterpolaton were the ponts at x = 845, 865, and 885, and, for the second nterpolaton, the values at x = 95, 945, and 965. These choces are seen to have only a sall effect on the nterpolated values. Interpolaton polynoal Results Interpolaton x Values Polynoals Used Lnear Quadratc Quadratc Cubc 853.079.044.030.036 96 0.64 0.60 0.6 0.67 b. Use the LINEST functon to fnd the regresson coeffcents for the data shown on the Regresson tab of the workbook for ths assgnent and use the as descrbed n the steps below.. Obtan the regresson coeffcents for y as a functon of three varables, x, x, and x 3; dentfy the regresson coeffcents and ther standard errors on the worksheet. These results, coped fro the worksheet, are shown below. LINEST Functon Results Slopes b 3 for x 3 b for x b for x Intercept, b 0 0.000654 9.03E-05 0.30.449 Standard Errors for frst row 0.00086 0.00077 0.70 0.497 R and s y x values 0.04055 0.8353 #N/A #N/A F statstc/degrees of freedo.345 65 #N/A #N/A Sus of squares 4.8659 5.3 #N/A #N/A. Once you have obtaned these coeffcents, use the to copute the estated y values for all the data ponts. Use these estated values to copute the R coeffcent for the regresson and copare t to the value gven by LINEST.

Soluton to prograng assgnent fve ME309, L. S. Caretto, Sprng 04 Page 4 These estated values of y (yhat) are coputed as.449 + 0.30x + 9.03x0-5 x + 0.000654x3. The ean value of y s found to be.8, usng the average functon of Excel. Once these values are found the R ter s coputed fro the usual equaton, shown below. R N N ( y ( y yˆ y) The coputed value agrees wth the one produced by LINEST. The value of R = 0.04055 shows that ths s not a good ft!. Use the TINV functon wth a confdence level of 95% to fnd the confdence lts for the regresson coeffcents. The confdence ntervals for the regresson coeffcents are for a two-sded test. The Excel calculaton of the t-statstc for a two-sded test, at any confdence level, L, s found by the functon call T.INV.T(-L,df) [or the copatblty functon TINV(-L,df)], where df s the degrees fo freedo. For a 95% confdence level and the degrees of freedo returned by lnest we use the functon call TINV(0.05, 65); ths returns a value of.974. Ths s ultpled by the standard error, gvng the followng ranges for the slopes: b0 =.45.6, b = 0.30 0.458, b = 9.03x0-5 7.8x0-5, b3 = 0.000654 0.009. The fact that these confdence levels are larger than the values of the regresson coeffcents s another ndcator that ths s a poor ft. 3. The followng assgnent can be done on an Excel worksheet or n the MATLAB coand wndow, as you prefer. f f ' f f ' f 8 f 8 f f 4 O( h ) f Oh h h f f '' f 6 f 30 f 6 f f 4 Oh f Oh '' f h ) h Use each forula to copute the dervatves of cos(x) at x = for a range of h values fro 0. to 0-0. Plot the errors (the dfference between the nuercal result and the correct value of dcos(x)/dx = -sn(/)) on a log-log plot and verfy that the order of the error s correct. Identfy the locatons on the plot where the roundoff error begns to occur. The table and graph below show the typcal behavor of the error for the gven case at x =. The shaded areas n the table show the areas where roundoff error plays a role and the relatonshp between error and order s not followed. The relatonshp between order and error s shown by the table entres for larger step szes (below the shaded areas.) The table also shows unusual results for x = /. Ths calculaton was not requred for the assgnent; t s shown here because of the unusual results for the second dervatve. For the cosne, d cos(x)/dx = cos(x). Ths s zero at x = /. The nuercal coputaton of ths dervatve uses the zero value of cosne at x = / and the reander of the coputaton uses values at / kh (where k = or ). The values at / kh for any k are opposte n sgn and ther addton n the fnte dfference expresson causes the to cancel gvng the correct value of zero for alost any step sze. In ths case, the expected relatonshp between step sze and error does not occur. Ths exaple s ncluded n ths soluton as a warnng that fnte-dfference results ay have exceptonal cases where the relatonshp between order and step sze does not occur. Download the workbook pa5soln.xls to see the actual worksheet calculatons.

Soluton to prograng assgnent fve ME309, L. S. Caretto, Sprng 04 Page 5 The results for the varous cases can be suarzed as follows: For the second-order frst dervatve at x = and x = /, between h = 0. and h = 0.00, the error decreases by a factor of 0 as the step sze s cut by a factor of 0. (At x = /, ths behavor contnue to a step sze of 0.000.) For the fourth-order frst dervatve, at both x = and x = /, between h = 0. and h = 0.0, the error decreases by a factor of 0 4 as the step sze s cut by a factor of 0. For the second-order second dervatve at x =, between h = 0. and h = 0.00, the error decreases by a factor of 0 as the step sze s cut by a factor of 0. For the fourth-order second dervatve at x =, between h = 0. and h = 0.0, the error decreases by a factor of 0 4 as the step sze s cut by a factor of 0. Step sze Error Results for Cosne Dervatves Errors Values at x = / Errors Values at x = Frst Dervatves Second Dervatves Frst Dervatves Second Dervatves nd Order 4th Order nd Order 4th Order nd Order 4 th Order nd Order 4 th Order E-0 8.7E-08 8.7E-08 6.3E-7 6.3E-7.03E-07 3.88E-07 5.40E-0 5.40E-0 E-09 8.7E-08.0E-07 6.3E-7 6.3E-7.9E-08.78E-08.E+0.96E+0 E-08 6.08E-09 9.78E-09 6.3E-7 6.3E-7 3.03E-09 3.03E-09 5.40E-0 5.40E-0 E-07 5.84E-0 9.54E-0 6.3E-7 6.3E-7 3.06E-0 6.76E-0.48E-0.E-0 E-06 8.4E-.9E-0 6.3E-7 6.3E-7.75E- 6.45E- 6.78E-05.90E-04 E-05.0E-.03E- 6.3E-7 6.3E-7.09E-.09E- 3.7E-06 3.7E-06 E-04.67E-09.0E-3 6.3E-7 6.3E-7.40E-09.3E-3 3.03E-08 4.5E-08 E-03.67E-07.80E-3 6.3E-7.80E-4.40E-07 5.78E-4 4.5E-08.57E-0 E-0.67E-05 3.33E-0 6.57E-5 6.75E-5.40E-05.80E-0 4.50E-06 5.96E- E-0.67E-03 3.33E-06 3.00E-6.44E-6.40E-03.80E-06 4.50E-04 6.00E-07