Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.

Slides:



Advertisements
Similar presentations
Splines and Piecewise Interpolation
Advertisements

Lecture 5 Fixed point iteration Download fixedpoint.m From math.unm.edu/~plushnik/375.
Chapter 6: Roots: Open Methods
Part 2 Chapter 6 Roots: Open Methods
MATLAB Optimization Greg Reese, Ph.D Research Computing Support Group Miami University.
Numerical Solution of Nonlinear Equations
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 One-Dimensional Unconstrained Optimization Chapter.
Ch11 Curve Fitting Dr. Deshi Ye
Mathematics1 Mathematics 1 Applied Informatics Štefan BEREŽNÝ.
ES 240: Scientific and Engineering Computation. InterpolationPolynomial  Definition –a function f(x) that can be written as a finite series of power functions.
Lecture 11 Chap. 15. Outline Interpolation – Linear Interpolation – Cubic Spline Interpolation – Extrapolation 15.2 Curve.
Numerical Operations S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: Optimization Toolbox.
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
ENGG 1801 Engineering Computing MATLAB Lecture 7: Tutorial Weeks Solution of nonlinear algebraic equations (II)
Nonlinear Algebraic Systems 1.Iterative solution methods 2.Fixed-point iteration 3.Newton-Raphson method 4.Secant method 5.Matlab tutorial 6.Matlab exercise.
Linear programming Lecture (4) and lecture (5). Recall An optimization problem is a decision problem in which we are choosing among several decisions.
CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Root Finding The solution of nonlinear equations and systems Vageli Coutsias, UNM, Fall ‘02.
Part 2 Chapter 7 Optimization
ENCI 303 Lecture PS-19 Optimization 2
84 b Unidimensional Search Methods Most algorithms for unconstrained and constrained optimisation use an efficient unidimensional optimisation technique.
Extrapolation Models for Convergence Acceleration and Function ’ s Extension David Levin Tel-Aviv University MAIA Erice 2013.
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
1 M ATLAB Short Course Part (2). 2 Elementary Math Function abs, sign: Absolute value and Signum Function sin, cos, asin, acos…: Triangular functions.
LINEAR ALGEBRA Matrix analysis Linear equations Eigenvalues and singular values Matrix functions.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
CHAPTER 3 NUMERICAL METHODS
6.094 Introduction to programming in MATLAB Danilo Šćepanović IAP 2008 Lecture 3 : Solving Equations and Curve Fitting.
Analyzing Functions (4.16) y=f(x) MATLAB. Functional Analysis includes: Plotting and evaluating a function Finding extreme points Finding the roots (zeros.
Newton’s Method, Root Finding with MATLAB and Excel
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Approximation Algorithms Department of Mathematics and Computer Science Drexel University.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
More Functions in MATLAB. Functions that operate on other functions A function F() can take another function G() as an argument by using a notation:
Mohiuddin Ahmad SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)
MODEL FITTING jiangyushan. Introduction The goal of model fitting is to choose values for the parameters in a function to best describe a set of data.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
Root Finding UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
MATLAB Numerical Basics. Roots of Polynominals MATLAB can find all roots (both real and imaginary) of polynominals. Store coefficients in a vector v =
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 2 - Chapter 7 Optimization.
Linear programming Lecture (4) and lecture (5). Recall An optimization problem is a decision problem in which we are choosing among several decisions.
Lecture 29: Modeling Data. Data Modeling Interpolate between data points, using either linear or cubic spline models Model a set of data points as a polynomial.
Introduction to Programming for Mechanical Engineers
Working with Data in MATLAB
The formulae for the roots of a 3rd degree polynomial are given below
The formulae for the roots of a 3rd degree polynomial are given below
Interpolation Methods
Chapter 15 Curve Fitting : Splines
4.2 Polynomial Functions and Models
Root finding.
ENGG 1801 Engineering Computing
Chapter 7: Optimization
Splines and Piecewise Interpolation
Applications of User Defined functions in MATLAB
Numerical Analysis Lecture 26.
Interpolation Methods
Curve fit metrics When we fit a curve to data we ask:
Curve fit metrics When we fit a curve to data we ask:
INTERPOLATION For both irregulary spaced and evenly spaced data.
The formulae for the roots of a 3rd degree polynomial are given below
Part 4 - Chapter 13.
Part 2 Chapter 7 Optimization
The formulae for the roots of a 3rd degree polynomial are given below
The formulae for the roots of a 3rd degree polynomial are given below
Presentation transcript:

Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate

Outline Finding roots with MATLAB Interpolation Numerical Integration Optimization Problems: Minimizing Functions of One Variable; Minimizing Functions of Several Variables; Linear Programming

Root finding Computing roots of the polynomials Polynomials are represented in MATLAB by their coefficients in the descending order of powers. For instance, the cubic polynomial p(x) = 3x 3 + 2x is represented as p = [ ]. Its roots can be found using function roots. >> format short >> r = roots(p) r = i i

Let now f be an one variable function f=f(x). MATLAB function fzero computes a zero of the function f using user supplied initial guess. In the following example let f(x) = cos(x) – x. First we define a function y = f 1 (x) function y = f1(x) y = cos(x) - x; To compute its zero we use MATLAB function fzero >> format long >>r = fzero('f1', 0.5) r = Name of the function whose zero is computed is entered as a string. Second argument of function fzero is the initial approximation of r. Finding zeros using MATLAB function fzero f=0

Function fzero A user can enter a two-element vector that designates a starting interval. In our example we choose [ 0 1] as a starting interval to obtain r = fzero('f1', [0 1]) r = One can check last result using function feval err = feval('f1', r) err =0 By adding the third input parameter tol you can force MATLAB to compute the zero of a function with the relative error tolerance tol. In our example we let tol = to obtain rt = fzero('f1',.5, 1e-3) rt =

Function fzero function f = myf(x) f = sin(x) - х.^2.*cos(x); >> x1=fzero ('myf', -5) x1 = >> x2=fzero ('myf', 0.1) x2 = e-019 >> x3=fzero ('myf', 5) x3 = f=0

Systems of nonlinear equations MATLAB function fsolve computes solution of this system as well. For more information help fsolve

Systems of nonlinear equations function F=mysys(x) F(1)=x(1)*(2-x(2))-cos(x(1))*exp(x(2)); F(2)=2+x(1)-x(2)-cos(x(1))-exp(x(2)); >> [x,f]=fsolve('mysys', [0 0]) x = f = 1.0e-011 *

Interpolation Given set of n+1 points x k, y k, k=(0…n), with x 0 < x 1 < … < x n, find a function f(x) whose graph interpolates the data points, i.e., f(x k ) = y k, for k = 0, 1, …, n. The general form of the function interp1 is yi = interp1(x, y, xi, method), where the vectors x and y are the vectors holding the x- and the y- coordinates of points to be interpolated, respectively, x i is a vector holding points of evaluation, i.e., y i = f(x i ) and method is an optional string specifying an interpolation method. The following methods work with the function interp1:  Nearest neighbor interpolation, method = 'nearest'. Produces a locally piecewise constant interpolant.  Linear interpolation method = 'linear'. Produces a piecewise linear interpolant.  Cubic spline interpolation, method = 'spline'. Produces a cubic spline interpolant.  Cubic interpolation, method = 'cubic'. Produces a piecewise cubic polynomial.

Interpolation In this example, the following points (x k, y k ) = (k/5, sin(2k)), k = 0, 1, …, 5, x = 0:pi/5:pi; y = sin(2.*x); are interpolated using the 'cubic' method of interpolation. The interpolant is evaluated at the following points xi = 0:pi/100:pi; yi = interp1(x, y, xi, 'cubic'); Points of interpolation together with the resulting interpolant are displayed below plot(x, y, 'o', xi, yi), title('Cubic interpolant of y = sin(2x)')

Numeric Integration Two MATLAB functions quad('f ', a, b, tol) and quad8('f ', a, b, tol) are designed for numerical integration of the univariate functions. The input parameter 'f' is a string containing the name of the function to be integrated from a to b. The fourth input parameter tol is optional and specifies user's chosen relative error in the computed integral. >> quad('sin',0,pi/2) ans = >> quad('sin',0,pi/2, ) ans = The default accuracy is function f=fint(x) f=exp(-x.^2); >> quad('fint',0,1) ans =

Numeric Integration of the bivariate functions Function dblquad computes a numerical approximation of the double integral where D = {(x, y): a < x< b, c< y <d} is the domain of integration. Syntax of the function is dblquad (fun, a, b, c, d, tol), where the parameter tol has the same meaning as in the function quad.

Numeric Integration of the bivariate functions The M-file esin is used to evaluate function f: function z = esin(x,y); z = exp(-x.*y).*sin(x.*y); >>result = dblquad('esin', -1, 1, 0, 1) result =

Optimization The problem of optimality criterion finding is in a base of most managing protocols in modern telecom technologies. The optimization problem is the problem of finding the best solution from all feasible solutions (from Wikipedia, the free encyclopedia) This may correspond to maximizing profit in a company, or minimizing loss in a conflict. For Telecom, for example, it is necessary to minimize middle delivery of packages in a network; to maximize the productivity of telecom system; to minimize the cost of the using of resources of networks; to maximize a profit of the sale of telecommunications services.

Minimizing Functions of One Variable For a given mathematical function of a single variable coded in an M-file, you can use the fminbnd function to find a local minimum of the function in a given interval. If one needs a maximum he should to put minus before the function. [x,fval] = returns value of x in which the function myfun(x) has a minimum on the interval x1<x<x2 and returns fval, that is the value of the function in the minimum. function f = myfun(x) f =... % the function under consideration For minimizing one can use the following functions [x,fval] = 0 ) [x,fval] = x 0 ) where x 0 is initial guess.

Minimizing Functions of One Variable Find the minimum of the function f(x)=x 3 -2x-5 on the interval from 0 to 2 clear all; fplot('fun1',[0,2]); grid on; title('fun1'); xlabel('x'); ylabel('f(x)'); % fun1.m function f = fun1(x) f=x^3-2*x-5 Solution: x=0.8165; fval=

Minimizing Functions of One Variable For minimizing problem one can use the following functions [x,fval] = [x,fval] = x0) where x0 is initial guess. E.g., Find the minimum of the function f(x)=arctg(x 3 -2x-5) on the interval from -2 to 2 clear all; fplot('fun2',[-2,2]); grid on; title('fun2'); xlabel('x'); ylabel('f(x)'); Solution: x=0.8165; fval= Solution: x =-2; fval= % fun2.m function f=fun2(x) f=atan(x^3-2*x-5);

Minimizing Functions of Several Variables The fminsearch function minimizes a function of several variables. Syntax x = fminsearch(fun,x0) x = fminsearch(fun,x0,options) [x,fval] = fminsearch(...) Description fminsearch finds the minimum of a scalar function of several variables, starting at an initial estimate. This is generally referred to as unconstrained nonlinear optimization. x = fminsearch(fun,x0) starts at the point x 0 and finds a local minimum x of the function described in fun. x 0 can be a scalar, vector, or matrix.

Minimizing Functions of Several Variables Find the minimum of the function f(x)= 3x 2 + 2xy + y 2 +5 near the point [20, -20] clear all; x0 = [20,-20]; [x,fval] = % fun3.m function f = fun3(x) f = 3*x(1)^2 + 2*x(1)*x(2) + x(2)^2+5;

Linear Programming A linear programming problem (or LP in brief) is any decision problem of the form

Linear Programming First, enter the coefficients f = [-5; -4; -6] A = [ ]; b = [20; 42; 30]; lb = zeros(3,1); Next, call a linear programming routine: [x,fval] = linprog(f,A,b,[],[],lb) Optimization terminated successfully. x = fval =