1 / 18

CMPSC 200 Fall 2013 Lecture 34

CMPSC 200 Fall 2013 Lecture 34. November 11, 2013. Exams. Exams (and quizzes) are on the front table divided by section then sorted alphabetically Leave the band on to keep pile neat. Only take your exam. If you take an exam out of order put it back in order!.

astrid
Download Presentation

CMPSC 200 Fall 2013 Lecture 34

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMPSC 200 Fall 2013Lecture 34 November 11, 2013

  2. Exams Exams (and quizzes) are on the front table divided by section then sorted alphabetically Leave the band on to keep pile neat. Only take your exam. If you take an exam out of order put it back in order!

  3. Chapter 13 – Numerical Tehniques

  4. Interpolation If you are given a set of measurements for an independent variable (y) at known values for the dependent variable (x), interpolation can be used to estimate the y value for x value that was not measured as long as the x is within the known range

  5. Interpolation Suppose we have measured the a property, d, at the values of t = 0, 10, 20, 30 … 100 and we want to estimate what the property would be t of 52. Plot the data and use ginput Fit a straight line between points of t = 50 and 60 Built-in function interp1

  6. Example Suppose I have measured a property at temperatures of 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, and 100 C and obtained the results of 25, 70, 128, 178, 220, 275, 319, 375, 420, 480, and 525. Now I want an estimate of what the property would be at 52 C. Estimate = interp1(T,P,52) % for just 52. Estimate = interp1(T,P, [12 45 67 98]) % for array of values

  7. Different Types of Interpolation You can calculate the estimate using different mathematical models (Table 13.1) Each model will give you different answers.

  8. Interpolation Results Saw that using different methods, resulting in different results. So which should you use? Remember that they are all estimates. How good was your data? If your estimates are within the error window of your data, then all may be “reasonably valid. How will this estimate be used? Choose the estimate that will provide the “safest” result.

  9. Multidimensional Interpolation Suppose we know a series of y values for x values. For example let x have the values of 1 to 4 and y have the values 2, 4, 6, 8, and 10. If we know the values for table z x = 1 x =2 x = 3 x = 4y = 2 6 11.5 18.1 24.2y = 4 30 60.8 91 118y = 6 200 404 598 791y = 8 300 595 895 1197y =10 500 997 1510 2010

  10. Multidimensional Interpolation Can use interp2 function to estimate a value at a new x and y combination znew = interp2(x, y, z, newx, newy) Note that the 2-dimensional array z must have the same number of columns as elements in x and the same number of rows as the elements in y. There is also an interp3 function for 3-dimensional interpolation (need a 3-dimensional array of known values)

  11. Interpolation vs. Extrapolation Interpolation is used to estimate data within a known range. Extrapolation is used to estimate outside the known range (used with care). (In other fields may be called projections.)

  12. Fitting Curves to Data Simplest method is to try to fit a straight line, then use linear regression to get a format similar to y = mx + b where m is the slope and b is the y intercept. The slope may be calculated using(Sx * Sy - n S(x * y))/((Sx)2 – n S(x)2 )where n is the number of points The y intercept can then be calculated using(Sy – slope * Sx)/n or y - slope * x

  13. Goodness of Fit How well the line fits to the data may be determined by looking at the difference between the real points and points calculated using the slope and y intercept. Because actual points will probably be both above and below calculated line, and therefore have both positive and negative differences, use the square of the differences. S(ym - yc)2

  14. Example x y0.58 6.8601.16 8.975 1.48 9.9041.76 10.9552.04 12.0052.50 13.5122.76 14.6573.00 15.3403.30 16.1693.50 17.045

  15. What If Data Is Not Linear? • Try plotting on semi-log or log-log scales. • y = aebxplot ln y vs x then slope = b and y intercept would be a • Y =cxdplot ln y vs ln x then slope = d and y intercept would by ln(c) • Try using the inverse of x • y = a/x + c plot y vs 1/x then a would be the slope and c would be the intercept • Try using the inverse of both sides • y = ax/(b+x) plot 1/y vs 1/x then b/a would be the slope and 1/a would be the intercept.

  16. Using polyfit Function • Will return the coefficients of various orders of polynomials. • Format is polyfit(xvalues, yvalues, n) where n is the order of the polynomial. • Examples: • Polyfit(x,y,1) will return two values to correspond to the coefficients a1 and a0 for y = a1x + a0 . • Polyfit (x,y,3) will return 4 values to correspond to the coefficients a0, a1, a2, and a3 for y = a0x3 + a1x2 + a2x + a3

  17. polyval Function Allows you to take the coefficients from the polyfit function and the x values to calculate possible y values. yc = polyval(coeff,x)

  18. Caution! Using high order polynomials can cause odd fits. Carl Runge in 1901 demonstrated possible errors with a function often called Runge’s function f(x ) = 1/(1 + 25x2) Try linear, 3rd, 7th, an 10th, order polynomials with 11 points from -2 to 2.

More Related