Iteration method solving equations: Newton Iteration Method, and kalibana Iteration Method

Source: Internet
Author: User

In the Newton iteration formula, the approximate root x0 of the known equation f (x) = 0 is used, and f (x) near x0 is replaced by the first order Taylor Polynomial. therefore, the equation f (x) = 0 can be approximately expressed as p (x) = 0. The x1 represents the root of p (x) = 0, which is slightly different from the root of f (x) = 0. let's assume that x1 satisfies the process of solving the recurrence problem and obtains the iteration formula: this is the famous Newton iteration formula. The corresponding fixed point equation is the basic solution for Solving Linear Equations of linear equations using the Markov iteration formula: if the equations can be the same solution deformation as the calculation formula of the Markov iteration method: that is, algorithm code [cpp]/* code implementation of simple Iteration Methods */# include <iostream> # include <string> # include <cmath> using namespace std; double e = 2.718281818284; double f (double x) {return pow (e,-1 * x);} void SimpleDiedai (double x, double d) {double a = x; double B = f (a); int k = 0; // record the number of cycles while (a-B)> d) | (( A-B) <-1 * d) {cout <a <endl; a = B; B = f (a); k ++; if (k> 100) {cout <"Iteration failed! (The function may not converge) "<endl; return ;}} cout <B <endl; return ;}int main () {cout <"Enter the initial value x0 and the expected result precision:"; double x, d; cin> x> d; SimpleDiedai (x, d ); return 0;} code implementation of www.2cto.com/* Newton Iteration Method */# include <iostream> # include <string> # include <cmath> using namespace std; double e = 2.718281818284; double f (double x) {double a = pow (e,-1 * x); return x-(x-a)/(1 + );} void NewtonDiedai (double x, double d) {double a = x; double B = f (a); int k = 0; // record the number of cycles while (a-B)> d) | (a-B) <-1 * d) {cout <a <endl; a = B; B = f (a); k ++; if (k> 100) {cout <"Iteration failed! (The function may not converge) "<endl; return ;}} cout <B <endl; return ;}int main () {cout <"Enter the initial value x0 and the expected result precision:"; double x, d; cin> x> d; NewtonDiedai (x, d ); return 0;}/* Code Implementation of The KNN algorithm */# include <iostream> # include <iomanip> # include <string> # include <vector> using namespace std; // function evaluate the maximum value of double MaxOfList (vector <double> x) {double max = x [0]; int n = x. size (); for (int I = 0; I <n; I ++) if (x [I]> max) max = x [I]; return max ;} // yake Compared with the iteration formula void jakits (vector <double> A, vector <double> B, int n) {vector <double> X (n, 0 ); vector <double> Y (n, 0); vector <double> D (n, 0); int k = 0; // record the number of cycles do {X = Y; for (int I = 0; I <n; I ++) {double tem = 0; for (int j = 0; j <n; j ++) {if (I! = J) tem + = A [I] [j] * X [j];} Y [I] = (B [I]-tem) /A [I] [I]; cout <left <setw (8) <Y [I] <"" ;}cout <endl; k ++; if (k> 100) {cout <"Iteration failed! (It may be that the function does not converge) "<endl; return ;}for (int a = 0; a <n; a ++) {D [a] = X [a]-Y [a] ;}} while (MaxOfList (D)> 0.00001 | MaxOfList (D) <-0.00001); return ;} int main () {int n; cout <"Enter the number of unknown equations n:"; cin >>n; cout <endl; vector <double> A (n, vector <double> (n, 0); vector <double> B (n, 0 ); cout <"Enter the coefficient matrix of the equations:" <endl; for (int I = 0; I <n; I ++) {for (int j = 0; j <n; j ++) {cin> A [I] [j] ;}}cout <endl; cout <"Enter the value vector of the equations: "<endl; f Or (int k = 0; k <n; k ++) {cin> B [k];} cout <endl; cout <"the equations you entered are: "<endl; for (int a = 0; a <n; a ++) {for (int B = 0; B <n; B ++) {cout <A [a] [B] <";}cout <" "<B [a] <endl ;}cout <endl; cout <"the solutions of the equations obtained by the KNN iteration formula are as follows:" <endl; Jacob (A, B, n); return 0;} original records of the experiment process (1) A root x * near x = 0.5 is obtained by using the simple iteration method and the Newton Iteration Method, respectively. The accuracy is 0.00001 (input 0.5 0.000001). The result is obtained by using the simple iteration method: (input 0.5 0.000001) the Newton iteration method is used to obtain the result: X0 = 0.5x1 = 0.566311x2 = 0.567143 (2) solve the equations using the KNN iteration method. (3) (10-1-2-1 10-2-1-2 5) (7.2 8.3 4.2) Experiment Results and Analysis 1. iterative method is a method of successive approximation, this method uses a fixed formula-the so-called iteration formula to repeatedly correct the approximate value of the root to make it more accurate until the results meet the accuracy requirements. Iteration Method is a method for solving the solution of the function equation f (x) = 0. It solves the problem that the bipartite method cannot solve the problem of multiple root-level dual root, but it increases the convergence speed. The idea of iteration is the basic idea of solving problems in computing methods. 2. The root process of simple iterative method is divided into two steps. The first step is to provide a guess value of the root, that is, the so-called iteration initial value, and then gradually process the iteration initial value to the root that meets the accuracy requirements. The design idea of the iteration method is: f (x) = 0 is equivalent to a solution that gradually satisfies the accuracy of the iteration formula. In actual iterations, the solution of different iterative functions may affect the calculation of the exact solution, or even cannot be solved due to function divergence. When solving the problem, you can determine whether the function is divergent by judging the function, when writing code, you can determine the number of cycles-that is, when the cycle is too many times and not from the cycle, it is regarded as an endless loop, and the positive solution cannot be obtained. 3. Simple iterative methods tend to only converge linearly, in order to obtain an iteration format with hyper-linear convergence, the approximate substitution method is usually used, that is, the Newton formula. The iterative function-/Newton method is a step-by-step linearity method. From the experimental results, we can see that although the approximate formula is selected, the Newton iteration method can still obtain a high accuracy solution, and the Newton iteration method greatly improves the convergence speed. 4. The basic idea of Iterative Method for Solving Linear Equations is to combine the solutions of simultaneous equations into a set of independent linear expressions, which simplifies the problem, similar to the simple iterative method, it has some limitations to solve the equations by using the same formula. For example, the coefficient matrix of the equations must have some special properties to ensure the convergence of the iteration process, however, iterative methods have obvious advantages at the same time-the algorithm is simple, so programming is easier, so it is still very useful in solving problems.

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.