Answer the question
In order to leave comments, you need to log in
Please help me figure out the error.
I need to find the roots of the equation by simple iteration, but as a result of running my program, an infinite number is obtained.
#include <iostream>
#include<cmath>
#include<cstdlib>
#include<stdio.h>
using namespace std;
void main() {
double xn,x0,eps,b;
eps = 0.0001;//точность вычисления корня
x0= 1;//начальное приближение
do {
xn = -(log(x0/3));//вычисляем очередное приближение
b = abs(xn - x0);//находим разницу между предыдущей итерацией и текущей
xn = x0;//предыдущую итерацию ставим равной текущей
} while (b > eps);//если условие верно,то продолжаем поиск
cout << "xn="<<xn<<'\n';
system("pause");
}
Answer the question
In order to leave comments, you need to log in
#include <iostream>
#include <cmath>
using namespace std;
int main() {
const double eps = 0.0001;
double x0 = 1;
double b = 0;
do {
const double xn = -log(x0 / 3);
b = abs(xn - x0);
x0 = xn;
} while (b > eps);
cout << "x = " << x0 << endl;
return 0;
}
xn = x0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question