Cmps1371 introduction to computing for engineers
Download
1 / 40

CMPS1371 Introduction to Computing for Engineers - PowerPoint PPT Presentation


  • 85 Views
  • Updated On :

CMPS1371 Introduction to Computing for Engineers. NUMERICAL METHODS. Interpolation. When you take data, how do you predict what other data points might be? Two techniques are : Linear Interpolation Cubic Spline Interpolation. Linear Interpolation.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CMPS1371 Introduction to Computing for Engineers' - havyn


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Cmps1371 introduction to computing for engineers l.jpg

CMPS1371Introduction to Computing for Engineers

NUMERICAL METHODS


Interpolation l.jpg
Interpolation

  • When you take data, how do you predict what other data points might be?

  • Two techniques are :

    • Linear Interpolation

    • Cubic Spline Interpolation


Linear interpolation l.jpg
Linear Interpolation

  • Assume the function between two points is a straight line

What is the corresponding value of y for this x?


Slide4 l.jpg

How do you find a point in between?

X=2, Y=?

Linear Interpolation – Connect the points with a straight line to find y


Matlab code l.jpg
MATLAB Code

  • interp1 is the MATLAB function for linear interpolation

  • First define an array of x and y

  • Now define a new x array, that includes the x values for which you want to find y values

  • new_y = interp1(x,y,x_new)


Slide8 l.jpg

Both measured data points and interpolated data were plotted on the same graph. The original points were modified in the interactive plotting function to make them solid circles.


Cubic spline l.jpg
Cubic Spline on the same graph. The original points were modified in the interactive plotting function to make them solid circles.

  • A cubic spline creates a smooth curve, using a third degree polynomial

We can get an improved estimate by using the spline interpolation technique


Slide11 l.jpg

Cubic Spline Interpolation. The data points on the smooth curve were calculated. The data points on the straight line segments were measured. Note that every measured point also falls on the curved line.


Curve fitting l.jpg
Curve Fitting curve were calculated. The data points on the straight line segments were measured. Note that every measured point also falls on the curved line.

  • There is scatter in all collected data

  • We can estimate the equation that represents the data by “eyeballing” a graph

  • There will be points that do not fall on the line we estimate


Slide13 l.jpg

This line is just a “best guess” curve were calculated. The data points on the straight line segments were measured. Note that every measured point also falls on the curved line.


Least squares l.jpg
Least Squares curve were calculated. The data points on the straight line segments were measured. Note that every measured point also falls on the curved line.

  • Finds the “best fit” straight line

  • Minimizes the amount each point is away from the line

  • It’s possible none of the points will fall on the line

  • Linear Regression


Polynomial regression l.jpg
Polynomial Regression curve were calculated. The data points on the straight line segments were measured. Note that every measured point also falls on the curved line.

  • Linear Regression finds a straight line, which is a first order polynomial

  • If the data doesn’t represent a straight line, a polynomial of higher order may be a better fit


Polyfit and polyval l.jpg
polyfit and polyval curve were calculated. The data points on the straight line segments were measured. Note that every measured point also falls on the curved line.

  • polyfit finds the coefficients of a polynomial representing the data

  • polyval uses those coefficients to find new values of y, that correspond to the known values of x



Slide18 l.jpg

Linear Regression best fit line(First Order)

Evaluate how close a fit you’ve achieved by taking the difference between the measured and calculated points, and adding them up


Slide19 l.jpg

Second Order Fit best fit line



Using the interactive curve fitting tools l.jpg
Using the Interactive Curve Fitting Tools best fit line

  • MATLAB 7 includes new interactive plotting tools.

  • They allow you to annotate your plots, without using the command window.

  • They include

    • basic curve fitting,

    • more complicated curve fitting

    • statistical tools


Use the curve fitting tools l.jpg
Use the curve fitting tools… best fit line

  • Create a graph

  • Making sure that the figure window is the active window select

    • Tools-> Basic Fitting

    • The basic fitting window will open on top of the plot




Slide26 l.jpg

Basic Fitting Window calculated data points


Slide27 l.jpg

You can also access the data statistics window from the figure menu bar.

Select

Tools->Data Statistics

from the figure window.

This window allows you to calculate statistical functions interactively, such as mean and standard deviation, based on the data in the figure, and allows you to save the results to the workspace.

Data Statistics Window


Differences and numerical differentiation l.jpg
Differences and Numerical Differentiation figure menu bar.

  • We can use symbolic differentiation to find the equation of the slope of a line

  • The diff function is easy to understand, even if you haven’t taken Calculus

  • It just calculates the difference between the points in an array


Slide29 l.jpg

The derivative of a data set can be approximated by finding the slope of a straight line connecting each data point



Approximating derivatives when you know the function l.jpg
Approximating Derivatives when you know the function case based on data measurements

  • If we know how y changes with x, we could create a set of ordered pairs for any number of x values. The more values of x and y, the better the approximation of the slope


Slide32 l.jpg

The slope of a function is approximated more accurately, when more points are used to model the function


Numerical differentiation l.jpg
Numerical Differentiation when more points are used to model the function

  • The derivative of a function is equal to the rate of change of f(x) with respect to x

Differentiating f(x)


Graph the derivative l.jpg
Graph the derivative when more points are used to model the function

  • Consider the function

    • f(x) = 0.0333x6 – 0.3x5 – 1.3333x4 + 16x3 – 187.2x


Slope of f x and f x l.jpg
Slope of f(x) and f’(x) when more points are used to model the function


Critical points l.jpg
Critical Points when more points are used to model the function

  • We can compute the compute the location of the functions critical points (points of zero slope)

    >> product = df(1:end-1) .* df)2:end);

    >> critical = xd(find(product < 0));

    critical =

    -5.2000 -1.9000 2.6000 5.8000 6.2000


Numerical integration l.jpg
Numerical Integration when more points are used to model the function

  • MATLAB handles numerical integration with two different quadrature functions

  • quad

  • quadl


An integral is often thought of as the area under a curve l.jpg
An integral is often thought of as the area under a curve when more points are used to model the function

The area under a curve can be approximated using the trapezoid rule.


Quadrature functions l.jpg
Quadrature functions when more points are used to model the function

  • quad uses adaptive Simpson quadrature

  • quadl uses adaptive Lobatto quadrature

  • Both functions require the user to enter a function in the first field.

    • called out explicitly as a character string

    • defined in an M-file

    • anonymous function.

  • The last two fields in the function define the limits of integration


ad