TheAlgorithms-C-Plus-Plus/computer_oriented_statistical_methods/false-position.cpp
苏淞丰 0e492fec2f #include<iosteream.h> --> <iostream> (#687)
* #include<iosteream.h> --> <iostream>

* CPP --> cpp

* Delete false-position.CPP

* delete tab

* delete CPP

* Delete false-position.CPP

* Delete false-position.cpp

* create cpp

* system("clear");
2019-12-22 15:50:33 +01:00

36 lines
794 B
C++

#include<stdlib.h>
#include <math.h>
#include <iostream>
float eq(float i) {
return (pow(i, 3) - (4 * i) - 9); // origial equation
}
int main() {
float a, b, z, c, m, n;
system("clear");
for (int i = 0; i < 100; i++) {
z = eq(i);
if (z >= 0) {
b = i;
a = --i;
goto START;
}
}
START:
std::cout << "\nFirst initial: " << a;
std::cout << "\nSecond initial: " << b;
for (int i = 0; i < 100; i++) {
float h, d;
m = eq(a);
n = eq(b);
c = ((a * n) - (b * m)) / (n - m);
a = c;
z = eq(c);
if (z > 0 && z < 0.09) { // stoping criteria
goto END;
}
}
END:
std::cout << "\n\nRoot: " << c;
system("pause");
}