Solution of equations, Newton iteration and dichotomy

Source: Internet
Author: User

Newton Iteration

#include <iostream>#include<string.h>#include<math.h>using namespacestd;floatFfloatx) {    return(Pow (x,3)-5*pow (x,2)+ -*x+ the);}floatF1 (floatx) {    return(3*pow (x,2)-5*x+ -);}intMain () {//x*x*x-5*x*x+16*x+80;    floatx=1, X1,y1,y2; CIN>>x;  Do{x1=x; Y1=f (x); Y2=F1 (x1); X=x1-y1/Y2; } while(Fabs (X-X1) >=0.000001); cout<<x1<<Endl; System ("Pause"); return 0;}

If you want to calculate the root under 3, then the equation is x*x-3=0;

Fabs the absolute value of floating-point numbers

The equation is solved by the dichotomy method:

#include <iostream>#include<math.h>using namespacestd;DoubleFDoublex) {    returnPow (x,x)-Ten;}intMain () {DoubleA=2, b=3, limit=0.00001;  while((B-A) >limit) {        if(f (a+b)/2) *f (b) <0) {a= (a+b)/2; }        Else //Same numberb= (A+B)/2; } cout<<a<<" "<<b<<Endl; System ("Pause"); return 0;}

x^x=10;

Solution of equations, Newton iteration and dichotomy

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.