1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Elementary mathematical and computational tools for electrical and computer engineers using Matlab - Chapter 5 potx

22 328 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 22
Dung lượng 168,71 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

© 2000 by CRC Press LLC 5 Root Solving and Optimization Methods In this chapter, we first learn some elementary numerical techniques and the use of the fsolve and fzero commands from the

Trang 1

© 2000 by CRC Press LLC

5

Root Solving and Optimization Methods

In this chapter, we first learn some elementary numerical techniques and the

use of the fsolve and fzero commands from the MATLAB library to

obtain the real roots (or zeros) of an arbitrary function Then, we discuss the

use of the MATLAB command roots for finding all roots of a polynomial Following this, we consider the Golden Section method and the fmin and

fmins MATLAB commands for optimizing (finding the minimum or mum value of a function) over an interval Our discussions pertain exclu-sively to problems with one and two variables (input) and do not include theimportant problem of optimization with constraints

maxi-5.1 Finding the Real Roots of a Function

This section explores the different categories of techniques for finding the realroots (zeros) of an arbitrary function We outline the required steps for com-puting the zeros using the graphical commands, the numerical techniquesknown as the Direct Iterative and the Newton-Raphson methods, and the

built-in fsolve and fzero functions of MATLAB.

5.1.1 Graphical Method

In the graphical method, we find the zeros of a single variable function byimplementing the following steps:

1 Plot the particular function over a suitable domain

2 Identify the neighborhoods where the curve crosses the x-axis

(there may be more than one point); and at each such point, thefollowing steps should be independently implemented

3 Zoom in on the neighborhood of each intersection point by

repeated application of the MATLAB axis or zoom commands.

Trang 2

4 Use the crosshair of the ginput command to read the coordinates

of the intersection

In problems where we desire to find the zeros of a function that depends

on two input variables, we follow (conceptually) the same steps above, butuse 3-D graphics

In-Class Exercises

Pb 5.1 Find graphically the two points in the x-y plane where the two

sur-faces, given below, intersect:

(Hint: Use the techniques of surface and contour renderings, detailed in

Chapter 1, to plot the zero height contours for both surfaces; then read off theintersections of the resulting curves.)

Pb 5.2 Verify your graphical answer to Pb 5.1 with that you would obtain

analytically

5.1.2 Numerical Methods

This chapter subsection briefly discusses two techniques for finding the zeros

of a function in one variable, namely the Direct Iterative and the Raphson techniques We do not concern ourselves too much, at this point,with an optimization of the routine execution time, nor with the inherent lim-its of each of the methods, except in the most general way Furthermore, toavoid the inherent limits of these techniques in some pathological cases, weassume that we plot each function under consideration, verify that it crosses

Newton-the x-axis, and satisfy ourselves in an empirical way that Newton-there does not seem

to be any pathology around the intersection point before we embark on theapplication of the following algorithms These statements will be made morerigorous to you in future courses in numerical analysis

This is a particularly useful technique when the equation f(x) = 0 can be cast

Trang 3

F(x) is then called an iteration function, and it can be used for the generation

where 0 ≤ s < 1; that is, the changes in the value of the function are smaller

than the changes in the value of the arguments To prove that under theseconditions, the iterative function possesses a fixed point (i.e., that ultimatelythe difference between two successive iterations can be arbitrarily small) thatcan be immediately obtained from the above contraction condition [Eq (5.3)]

PROOF Let the x guess be the first term in the iteration, then:

(5.4)but since

(5.5)then

(5.6)Similarly,

(5.7)translates into

Trang 4

but, because s is a non-negative number smaller than 1, the right-hand-side of the inequality in Eq (5.9) can be made, for large enough value of m, arbitrarily

small, and the above iterative procedure does indeed converge to a fixed point

in this case because the difference between two sines is always smaller thanthe difference between their arguments The fixed point can then be obtained

by the following MATLAB program:

As can be noticed from the above printout, about 11 iterations were required

to get the value of the fixed point accurate to one part per 10,000

error tolerance is to write the program with the while command, where we

can specify the tolerance level desired

This method requires a knowledge of both the function and its derivative.The method makes use of the geometrical interpretation of the derivativebeing the tangent at a particular point, and that the tangent is the limit of the

chord between two close points on the curve It is based on the fact that if f(x1)

and f(x2) have opposite signs and the function f is continuous on the interval

Trang 5

[x1, x2], we know from the Intermediate Value theorem of calculus that there

is at least one value x c between x1 and x2, such that f(x c) = 0 A sufficient

con-dition for this method to work is that f ′(x) and f ″(x) have constant sign on an open interval that contains the solution f (x) = 0; in that case, any starting

point that is close enough to the solution will give successive Newton’sapproximations that converge to the solution

Let x guess and x have the same meaning as in the iterative method; therefore,

f(x) = 0, and the definition of the derivative results in the equation:

(5.12)This relation can now be the basis of an iterative function given by:

(5.13)

The fixed point can be obtained, in general, for the same initial guess and erance, in a smaller number of iterations in the Newton-Raphson methodthan in the Direct Iteration method

tol-In-Class Exercise

Pb 5.3 Write a routine to find the zero of the function y = x – sin(x) – 1 using

the Newton-Raphson algorithm

Pb 5.4 Compare the answers from the present algorithm with that of theDirect Iterative method, at each iteration step, in the search for the zeros of

the function y = x – sin(x) – 1, and comment on which of the two methods

appears to be more effective and converges faster

Example 5.2

Apply the Newton-Raphson method to find the voltage-current relation in adiode circuit with an ac voltage source

voltage current curve that is described, for voltage values larger than thereverse breakdown potential (a negative quantity), by:

(5.14)

where I sis the reverse saturation current (which is typically on the order of

10–6 mA), and kT is the average thermal energy of an electron divided by its

f x guess

Trang 6

charge at the diode operating temperature (equal to 1/40 V at room ature) An important application of this device is to use it as a rectifier (adevice that passes the current in one direction only) (Can you think of a prac-tical application for this device?)

temper-The problem we want to solve is to find the current through the circuit(shown in Figure 5.1) as a function of time if we are given a sinusoidal time-dependent source potential

The other equation, in addition to Eq (5.14) that we need in order to set the

problem, is Ohm’s law across R This law, as previously noted, states that the

current passing through a resistor is equal to the potential difference acrossthe resistor, divided by the value of the resistance:

where the potential across the diode is the unknown

In the Newton-Raphson method, we also need for our iteration the tive of this function:

deriva-(5.17)

For a particular value of V s , we need to determine v and, from this value

of the potential across the diode, we can determine the current in the cuit However, because we are interested in obtaining the current through

υ

i V v R s

R s

Trang 7

the diode for a source potential that is a function of time, we need to repeatthe Newton-Raphson iteration for each of the different source voltage val-ues at the different times The sequence of the computation would proceed

as follows:

1 Generate the time array

2 Generate the source potential for the different elements in the timearray

3 For each time array entry, find the potential across the diode usingthe Newton-Raphson method

4 Obtain the current array from the potential array

5 Plot the source potential and the current arrays as a function of thetime array

Assuming that the source potential is given by:

and that f = 60 Hz, V0 = 5 V, kT = 0.025 V, R = 500 Ω, and the saturation current

I sis 10–6 mA; the following script M-file finds the current in this circuit:

((1/kT)*Is*exp((1/kT)*v(:,k))+1/R);

i(:,k+1)=(Vs(:,k+1)-v(:,k+1))/R;

end

plot(t,1000*i(:,K),'b',t,Vs(:,K),'g')

Trang 8

The current (expressed in mA) and the voltage (in V) of the source willappear in your graph window when you execute this program.

Homework Problem

Pb 5.5 The apparent simplicity of the Newton-Raphson method is verymisleading, suffice it to say that some of the original work on fractals startedwith examples from this model

a. State, to the best of your ability, the conditions that the function,its derivative, and/or the original guess should satisfy so that thisiterate converges to the correct limit Supplement your argumentswith geometric sketches that illustrate each of the pathologies

zero of the function:

c. Illustrate, with a simple sketch, the reason that this method does

not work in part (b).

5.1.3 MATLAB fsolve and fzero Built-in Functions

Next, we investigate the use of the MATLAB command fsolve for finding

the zeros of any function We start with a function of one variable

The recommended sequence of steps for finding the zeros of a function is

as follows:

1 Edit a function M-file for the function under consideration.

2 Plot the curve of the function over the appropriate domain, andestimate the values of the zeros

3 Using each of the estimates found in (2) above as an initial “guess,”

use the command fsolve to accurately find each of the roots The

syntax is as follows:

xroot=fsolve('funname',xguess)

the zero of a function of one variable However, we used fsolve in the text

above because it can only be used for the two-variables problem

y= x− 3

Trang 9

In the following application, we use the command fzero to find the zeros

of a Bessel function, and learn in the process some important facts about thisoften-used special function of applied mathematics

Application

Bessel functions are solutions to Bessel’s differential equations of order n,

given by:

(5.19)

There are special types of Bessel functions referred to as “of the first, second,

and third kinds.” Bessel functions of integer order appear, inter alia, in the

expression of the radiation field in cylindrically shaped resonant cavities, and

in light diffraction from a circular hole Bessel functions of half-integer indices

(see Pb 2.26) appear in problems of spherical cavities and scattering of

elec-tromagnetic waves Airy functions, a member of the Bessel functions family,appear in a number of important problems of optics and quantum mechanics.The recursion formula that relates the Bessel function of any kind of a cer-tain order with those of the same kind of adjacent orders is

where Z n (x) is the generic designation for all kinds of Bessel functions.

In this application, we concern ourselves only with the Bessel function of

besselj(n,x) In the present problem, we are interested in the root ture of the Bessel function of the first kind and of zero order

struc-In the program that follows, we call the Bessel function from the MATLABlibrary; however, we could have generated it ourselves using the techniques

of Section 4.7 because we know the ODE that it satisfies, and its value and

that of its derivative at x = 0, namely:

The problem that we want to solve is to find the zeros of J0(x) and compare

to these exact values those obtained from the approximate expression:

Trang 10

x0approx(k)=(pi/4)*p(k)+(1/(2*pi))*(p(k)^(-1))- (31/6)*(1/pi^3)*(p(k)^(-3))+

title('Error in Approximate Values of the Zeros')

As you can easily observe by examining Figure 5.2, the approximate series is

suitable for calculating all (except the smallest) zeros of the function J0(x)

cor-rectly to at least five digits

FIGURE 5.2

The first ten zeros of the Bessel function J0(x) Top panel: The values of the successive zeros (roots) of J0(x) Bottom panel: Deviation in the values of these zeros between their exact expressions and their approximate values as given in Eq (5.21).

Trang 11

Zeros of a Function in Two Variables

As previously noted, the power of the MATLAB fsolve function really

shines in evaluating the roots of multivariable functions

Example 5.3

Find the intersection in the x-y plane of the parabaloid and the plane given in

Pb 5.1

Solution:We follow these steps:

1 Use the contour command to estimate the coordinates of the

points of intersection of the surfaces in the x-y plane.

2 Construct the function M-file for two functions (z1, z2) having two

Trang 12

xyroots =

5 To find the second root, use the second value of xyguess, which

is the estimate of the other root, obtained from an examination of

the contour plot in step 1 of the fsolve command:

4

14

Trang 13

not be found analytically MATLAB has a built-in command that finds all theroots (real and complex) for any polynomial equation As previously noted,

the MATLAB command for finding the polynomial roots is roots:

r=roots(p)

In interpreting the results from this command, recall the Fundamental

Theo-rem of Algebra, which states the root properties of a polynomial of degree n

with real coefficients:

1 The nth polynomial admits n complex roots.

2 Complex roots come in conjugate pairs [If you are not familiarwith complex numbers and with the term complex conjugate (thelatter term should pique your curiosity), be a little patient Help is

on the way; Chapter 6 covers the topic of complex numbers].Inversely, knowing the roots, we can reassemble the polynomial The com-

mand is poly.

poly(r)

In-Class Exercise

Pb 5.14 Find the roots of the polynomial p = [1 3 2 1 0 3], and

com-pute their sum and product

Pb 5.15 Consider the two polynomials:

Find the value(s) of x at which the curves representing these polynomials

would intersect

Pb 5.16 Find the constants A, B, C, D, and a, b, c, d that permits the

follow-ing expansion in partial fractions:

Trang 14

resistor circuit [Figure 3.1] in which we wanted to find the maximum powerdelivered to a load resistor.) In this section, we will learn the simple Golden

Section rule and the use of the fmin command to solve the simplest forms

of this problem The important class of problems related to optimizing afunction, while satisfying a number of constraints, will be left to moreadvanced courses

Let us start by reminding ourselves of some terms definitions: The domain

is the set of elements to which a function assigns values The range is the set

of values thus obtained

DEFINITION Let I, the domain of the function f(x), contain the point c We

say that:

1 f(c) is the maximum value of the function on I if f(c) ≥ f(x) for all x ∈ I.

2 f(c) is the minimum value of the function on I if f(c) ≤ f(x) for all x ∈ I.

3 An extremum is the common designation for either the maximumvalue or the minimum value

Using the above definitions, we note that the maximum (minimum) may

appear at an endpoint of the interval I, or possibly in the interior of the

interval:

• If a maximum (minimum) appears at an endpoint, we describe thisextreme point as an endpoint maximum (minimum)

• If a maximum (minimum) appears in the interior of the interval,

we describe this extreme point as a local maximum (minimum)

• The largest (smallest) value among the maximum (minimum) ues (either endpoint or local) is called the global maximum (min-imum) and is the object of our search

val-We note, in passing, the equivalence of finding the local extremum of a tion with finding the zeros of the derivative of this function The followingmethods are suitable when this direct method is not suitable due to a number

Ngày đăng: 13/08/2014, 02:21

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN