Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.

Similar presentations


Presentation on theme: "1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept."— Presentation transcript:

1 1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept. http://www.bmabdelaty.faculty.zu.edu.eg/Default.aspx

2 In the previous lectures 2  Matlab Windows (workspace, m-file,…)  Working with Arrays  Mathematical Operations with Arrays  Using Script Files and Managing Data  Plotting data and functions.  Programming in Matlab.  User-defined functions.

3 Agenda 3  Polynomials  Curve Fitting  Interpolation.

4 Polynomials 4  Matlab representation of a polynomial:

5 Polynomials 5

6 Polynomials 6  Operations on polynomials:  Value of a polynomial.  Roots of a polynomial.  Addition, Multiplication and Division.  Derivatives of a polynomial.

7 Polynomials 7  Value of a polynomial: Example 1

8 8 Example 1: Solution Polynomials

9 Polynomials 9  Roots of a polynomial:

10 Polynomials 10  From roots to polynomial:

11 Polynomials 11  Addition of polynomials:  Two polynomials can be added (or subtracted) by adding (subtracting) the vectors of the coefficients. If the polynomials are not of the same order the shorter vector has to be modified to be of the same length as the longer vector by adding zeros in front.

12 Polynomials 12  Multiplication of two polynomials:

13 Polynomials 13  Division of two polynomials:

14 Polynomials 14  Derivatives of a polynomial:

15 Curve Fitting 15  Given: n points (x,y), it is required to write a polynomial of degree n-1 that passes throw all the points.  Using the polyfit function.  Polynomials can be used to fit data points in two ways. In one the polynomial passes through all the data points, and in the other the polynomial does not necessarily pass through any of the points, but overall gives a good approximation of the data.

16 Curve Fitting 16  Polyfit:

17 Curve Fitting 17  Example 2: Given a set of 7 points: (0.9,0.9), (1.5,1.5),(3,2.5),(4,5.1),(6,4.5),(8,4.9),(9.5,6.3) Let’s try to fit the points with polynomials of degrees 1 through 6.

18 Curve Fitting 18  Example 2:

19 Curve Fitting 19  Example 2:

20 20  Sometimes you have a set of data points, when plotted gives a close plot to a known function (i.e., power, logarithmic, exponential,…). Curve Fitting with functions

21 21 Curve Fitting with functions Examples of the functions:

22 22  Matlab must put the mentioned function in a linear form before using polyfit() : Curve Fitting with functions

23 23  What is the result? Help  Help: how can you estimate the function? Curve Fitting with functions

24 24  Example 3: Curve Fitting with functions

25 25  Example 3: Solution: Curve Fitting with functions First: you have to plot the points Since t (x-axis values) is linear, then we can guess that the exponential function may give a good fit

26 26  Example 3: Solution: Curve Fitting with functions Second: use polyfit() w = 5.9889*exp(-0.458 *t)

27 27  Example 3: Solution: Curve Fitting with functions w = 5.9889*exp(-0.458 *t)

28 Interpolation 28  Interpolation is the estimation of values between data points. MATLAB has interpolation functions that are based on polynomials, which are described here. And on Fourier transformation, but not discussed here.  One-dimensional interpolation:  If only two data points exist, the points can be connected with a straight line is and a linear equation (polynomial of first order) can be used to estimate values between the points.  As the number of points increases, a higher-order polynomial is required.

29 Interpolation 29  How does Matlab do it?  Instead of considering all the points in the data set (by using one polynomial that passes through all the points), only a few data points in the neighborhood where the interpolation is needed are considered. In this method, called spline interpolation, many low-order polynomials are used, where each is valid only in a small domain of the data set.

30 30 Interpolation

31 31 Interpolation  Example 4:

32 32 Interpolation  Example 4: Solution

33 33 Interpolation  Example 4: output:

34 Material & problems 34  We have covered (most of) Chapter 8 from Gilat.  Important self-reading: section 8.4  Problems you can try: Sample Problem 8-4 1—6, 14,15, 18,21,22


Download ppt "1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept."

Similar presentations


Ads by Google