Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <conio.h>
- #include <fstream>
- using namespace std;
- double func (double x){
- return (x*x+4*cos(x)-4);
- //return (2*x);
- }
- double der_func (double x){
- return(2*x-4*sin(x));
- }
- double bisequcie (double a,double b,double eps){
- double y;
- double xl=a;
- double xr=b;
- while (abs(xr-xl)>eps){ //точность
- y=(xl+xr)/2;
- if (func(y)==0) return y; //проверка на сходимость при начальном дроблении
- else if ((func(xl)<0 && func(y)>0) || (func(xl)>0 && func(y)<0)) //условие разных знаков на концах интервала
- //else if (func ((xl + xr) / 2) * func (xl) < func ((xl + xr) / 2)* func (xr))
- xr=y; else xl=y; //сокращаем интервал
- }
- return (xl+xr)/2;
- }
- double NEWTON (double x0,double eps){
- double x_prev=x0-eps;
- double x=x0;
- double buffer=0;
- while (abs (x - x_prev) * 2 > eps){
- x_prev=x;
- x=x-(func(x)/der_func(x));
- }
- return x;
- }
- int main (){
- setlocale (LC_ALL,"Russian");
- cout.precision (8);
- cout << "Решение по бисекциям : " << bisequcie (-7,7,0.00000001) <<endl;
- cout<< "Решение по Ньютону : "<<NEWTON(5,0.00000001);
- system ("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement