Newton Iteration matlab program [z]

Source: Internet
Author: User

1. Function

In this program, the Newton method is used to calculate the coefficient of high-order algebra.

F (x) = a0xn + a1xn-1 +... + An-1x + an =0 (= 0 ) (1)

In the initial valueX0A nearby root.

2.Instructions for use

(1) function statements

Y = newton_1 (A, N, x0, NN, eps1)

Call the M file newton_1.m.

(2) parameter description

A one-dimensional array of N + 1 elements. input parameters and store the equation coefficients by ascending power.

N integer, input parameter, equation order.

X0 real variable, input parameter, initial iteration value.

Nn integer variable, input parameter, maximum number of iterations allowed.

Eps1 real variables, input parameters, control the accuracy of the root.

3. Method Introduction

The Newton Method for Solving the nonlinear equation f (x) = 0 is an approximate method for linear nonlinear equations. Unfold f (x) near x0 to a Taylor series.

F (x) = f (x0) + (x-x0) f ˊ (x0) + (x-x0) 2 +...

Take its linear part as an approximate equation of the nonlinear equation f (x) = 0.

F (x0) + F weight (x0) (x-x0) = 0

If f Branch (x0) is less than 0, the solution is

X1 = x0-f (x0)/F done (x0)

Then, f (x) is expanded near X1 to the Taylor series, and its linear part is used as the approximate equation of f (x) = 0. If F (X1) is less than 0

X2 = x1-f (X1)/F release (X1)

In this way, an iteration sequence of the Newton method is obtained.

Xn + 1 = xn-F (Xn)/F forward (Xn)

4. Newton_1.m Program

Function Y = newton_1 (A, N, x0, NN, eps1)

X (1) = x0;

B = 1;

I = 1;

While (abs (B)> eps1 * x (I ))

I = I + 1;

X (I) = x (I-1)-n_f (a, n, x (I-1)/n_df (a, n, x (I-1 ));

B = x (I)-x (I-1 );

If (I> nn) error (neural nn is full response );

Return;

End

End

Y = x (I );

I

End

The n_f.m and n_df.m files called in the program are as follows:

Function y = n_df (a, n, x) % function of the first derivative of the equation
Y = 0.0;
For I = 1: n
Y = y + a (I) * (n + 1-i) * x ^ (n-I );
End

Function y = n_df (a, n, x)

Y = 0.0;

For I = 1: n

Y = y + a (I) * (n + 1-i) * x round (n-I );

End

5. Program notes

(1) The program calls the n_f.m and n_df.m files. N_f.m is the function of the Real-number algebra equation to be obtained, and n_df.m is the function of the first derivative of the equation. Written by the user.

(2) convergence speed of the Newton Iteration Method: IfF (x)There is a continuous Second-Order Derivative Near zero.F (x)And the initial value x0 is close to that of ε, So Newton Iteration converges, and its convergence speed is second-order, that is, the square convergence speed.

6. Example

Find the root of the following equation by Newton Method

F (x) = x3 + 2x2 + 10x-20

7. Running result

> A = [1, 2, 10,-20];

> N = 3;

> X0 = 1;

> Nn = 1000;

> Eps1 = 1e-8;

> Y = newton_1 (a, n, x0, nn, eps1)

Y =

1.20.8081078000073e + 000

I =

6

 

Original: http://www.ymlib.net/article/sort010/info-123.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.