Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
EnglishTI_MZ_CAPR(1ea429)2010.doc
Скачиваний:
17
Добавлен:
28.04.2019
Размер:
2.77 Mб
Скачать
      1. Chord method

The geometric meaning Chord method is to replace the chord of the curve y=f(x). Another approach is the intersection of the chord with the abscissa.

Figure 1.4 – Chord method

If [a,b] – a segment containing the root, the equation of the chord

For the point of intersection of the chord with the abscissa we have

,

taken for the next approximation to the root. Then choose one of the intervals , at the end of which the function has the values of different signs, ets…

Please note that all received one end of the intervals will be the same, namely the one on which sign function and the sign of the second derivative of the same. This end is called fixed, while the opposite end of the segment is taken as an initial approximation to the root. Let c - one of the ends of the segment, for which the condition , and - the initial value (the opposite end of the segment), then perform the iteration formula:

, k=0,1,2,…

1.3.3 Matlab function fzero and roots

Function fzero - find zero of a function of one variable.

Syntax

x = fzero(fun,x0)

x = fzero(fun,x0,options)

[x,fval] = fzero(...)

[x,fval,exitflag] = fzero(...)

[x,fval,exitflag,output] = fzero(...)

Description

x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. fun is a function handle for either an M-file function or an inline function.The value x returned by fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search terminates when the search interval is expanded until an Inf, NaN, or complex value is found.

If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1)) differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an interval guarantees fzero will return a value near a point where fun changes sign.

x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure options. You can define these parameters using the optimset function. fzero uses these options structure fields:

Display

Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final' displays just the final output; 'notify' (default) displays output only if the function does not converge.

FunValCheck

Check whether objective function values are valid.

'on' displays a warning when the objective function returns a value that is complex or NaN.

'off' (the default) displays no warning.

OutputFcn

Specify a user-defined function that the optimization function calls at each iteration.

TolX

Termination tolerance on x

[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.

[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition of fzero:

1 - Function converged to a solution x.

-1 - Algorithm was terminated by the output function.

-3 - NaN or Inf function value was encountered during search for an interval containing a sign change.

-4 - Complex function value was encountered during search for an interval containing a sign change.

-5 - fzero might have converged to a singular point.

[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the optimization:

output.algorithm Algorithm used

output.funcCount Number of function evaluations

output.intervaliterations Number of iterations taken to find an interval

output.iterations Number of zero-finding iterations

output.message Exit message

Using fzero for a function defined by inline command

The following command solves the equation

y = f(x) = x^3-5*x^2-x+2

starting from an initial guess of x = 4.

>>f=inline(‘x.^3-5*x.^2-x+2’);

>> fzero(f,4)

MATLAB returns the answer:

ans =

5.1190

Changing the initial guess to x = 2

>> fzero(f,2)

gives

ans =

0.5684

You can restrict the search to an interval by replacing the initial guess with an interval x€[3 6]:

z = fzero(f; [3 6])

Using fzero for a function defined in script file ‘fun’

Now, try solving the function defined in the script file fun.m.

>> x=fzero('fun', 4)

x =

5.1190

fzero uses a bisection approach to locating roots. Can you forsee any limitations to this? Try repeating the above with different initial conditions - how many roots can you locate?

MATLAB function roots

If the nonlinear algebraic system is a polynomial equation, we could use the MATLAB routine roots to find the zeros of the polynomial. Consider the same function f(x) = x3 - 5x2 -x +2 that we discussed earlier.

The user must create a vector of the coefficients of the polynomial, in descending order, p = [1 -5 -1 2]:

Then the user can type the following command roots(p) and MATLAB returns the roots.

EDU>> roots(p)

ans =

5.1190

-0.6874

0.5684

Confirm that x = 0.5684 is a root by typing f(0.5864).

EDU>> f(.5684)

ans =

-1.5495e-004

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]