Skip to content

Commit baea3b0

Browse files
committed
major corrections in the files - bad CPPLINT and non-compilable codes
1 parent 1e5b9f8 commit baea3b0

File tree

6 files changed

+143
-201
lines changed

6 files changed

+143
-201
lines changed
Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,40 @@
1-
#include <iostream.h>
2-
#include <conio.h>
3-
#include <math.h>
1+
#include <cmath>
2+
#include <iostream>
43

5-
float eq(float i)
6-
{
7-
return (pow(i, 3) - (4 * i) - 9); // original equation
4+
float eq(float i) {
5+
return (std::pow(i, 3) - (4 * i) - 9); // original equation
86
}
97

10-
void main()
11-
{
12-
float a, b, x, z;
13-
clrscr();
14-
for (int i = 0; i < 100; i++)
15-
{
16-
z = eq(i);
17-
if (z >= 0)
18-
{
19-
b = i;
20-
a = --i;
21-
goto START;
22-
}
23-
}
8+
int main() {
9+
float a, b, x, z;
2410

25-
START:
11+
for (int i = 0; i < 100; i++) {
12+
z = eq(i);
13+
if (z >= 0) {
14+
b = i;
15+
a = --i;
16+
break;
17+
}
18+
}
2619

27-
cout << "\nFirst initial: " << a;
28-
cout << "\nSecond initial: " << b;
29-
for (i = 0; i < 100; i++)
30-
{
31-
x = (a + b) / 2;
32-
z = eq(x);
33-
cout << "\n\nz: " << z << "\t[" << a << " , " << b << " | Bisect: " << x << "]";
20+
std::cout << "\nFirst initial: " << a;
21+
std::cout << "\nSecond initial: " << b;
22+
for (int i = 0; i < 100; i++) {
23+
x = (a + b) / 2;
24+
z = eq(x);
25+
std::cout << "\n\nz: " << z << "\t[" << a << " , " << b
26+
<< " | Bisect: " << x << "]";
3427

35-
if (z < 0)
36-
{
37-
a = x;
38-
}
39-
else
40-
{
41-
b = x;
42-
}
28+
if (z < 0) {
29+
a = x;
30+
} else {
31+
b = x;
32+
}
4333

44-
if (z > 0 && z < 0.0009) // stoping criteria
45-
{
46-
goto END;
47-
}
48-
}
34+
if (z > 0 && z < 0.0009) // stoping criteria
35+
break;
36+
}
4937

50-
END:
51-
cout << "\n\nRoot: " << x;
52-
getch();
38+
std::cout << "\n\nRoot: " << x;
39+
return 0;
5340
}

computer_oriented_statistical_methods/Newton_Raphson.CPP

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,37 @@
1-
#include <iostream.h>
2-
#include <conio.h>
3-
#include <math.h>
1+
#include <cmath>
2+
#include <iostream>
43

5-
float eq(float i)
6-
{
7-
return (pow(i, 3) - (4 * i) - 9); // original equation
4+
float eq(float i) {
5+
return (pow(i, 3) - (4 * i) - 9); // original equation
86
}
97

10-
void main()
11-
{
12-
float a, b, z, c, m, n;
13-
clrscr();
14-
for (int i = 0; i < 100; i++)
15-
{
16-
z = eq(i);
17-
if (z >= 0)
18-
{
19-
b = i;
20-
a = --i;
21-
goto START;
22-
}
23-
}
8+
int main() {
9+
float a, b, z, c, m, n;
10+
for (int i = 0; i < 100; i++) {
11+
z = eq(i);
12+
if (z >= 0) {
13+
b = i;
14+
a = --i;
15+
break;
16+
}
17+
}
2418

25-
START:
19+
std::cout << "\nFirst initial: " << a;
20+
std::cout << "\nSecond initial: " << b;
21+
for (int i = 0; i < 100; i++) {
22+
float h, d;
23+
m = eq(a);
24+
n = eq(b);
2625

27-
cout << "\nFirst initial: " << a;
28-
cout << "\nSecond initial: " << b;
29-
for (i = 0; i < 100; i++)
30-
{
31-
float h, d;
32-
m = eq(a);
33-
n = eq(b);
26+
c = ((a * n) - (b * m)) / (n - m);
27+
a = b;
28+
b = c;
3429

35-
c = ((a * n) - (b * m)) / (n - m);
36-
a = b;
37-
b = c;
30+
z = eq(c);
31+
if (z > 0 && z < 0.09) // stoping criteria
32+
break;
33+
}
3834

39-
z = eq(c);
40-
if (z > 0 && z < 0.09) // stoping criteria
41-
{
42-
goto END;
43-
}
44-
}
45-
46-
END:
47-
cout << "\n\nRoot: " << c;
48-
getch();
35+
std::cout << "\n\nRoot: " << c;
36+
return 0;
4937
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <cmath>
2+
#include <iostream>
3+
4+
float eq(float i) {
5+
return (std::pow(i, 3) - (4 * i) - 9); // original equation
6+
}
7+
float eq_der(float i) {
8+
return ((3 * std::pow(i, 2)) - 4); // derivative of equation
9+
}
10+
11+
int main() {
12+
float a, b, z, c, m, n;
13+
14+
for (int i = 0; i < 100; i++) {
15+
z = eq(i);
16+
if (z >= 0) {
17+
b = i;
18+
a = --i;
19+
break;
20+
}
21+
}
22+
23+
std::cout << "\nFirst initial: " << a;
24+
std::cout << "\nSecond initial: " << b;
25+
c = (a + b) / 2;
26+
27+
for (int i = 0; i < 100; i++) {
28+
float h;
29+
m = eq(c);
30+
n = eq_der(c);
31+
32+
z = c - (m / n);
33+
c = z;
34+
35+
if (m > 0 && m < 0.009) // stoping criteria
36+
break;
37+
}
38+
39+
std::cout << "\n\nRoot: " << z << std::endl;
40+
return 0;
41+
}
Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,28 @@
1-
#include <conio.h>
2-
#include <iostream.h>
3-
#include <math.h>
4-
float eq(float y)
5-
{
6-
return ((3 * y) - (cos(y)) - 2);
7-
}
8-
float eqd(float y)
9-
{
10-
return ((0.5) * ((cos(y)) + 2));
11-
}
121

13-
void main()
14-
{
15-
float y, x1, x2, x3, sum, s, a, f1, f2, gd;
16-
int i, n;
2+
#include <cmath>
3+
#include <iostream>
4+
5+
float eq(float y) { return ((3 * y) - (cos(y)) - 2); }
6+
float eqd(float y) { return ((0.5) * ((cos(y)) + 2)); }
177

18-
clrscr();
19-
for (i = 0; i < 10; i++)
20-
{
21-
sum = eq(y);
22-
cout << "value of equation at " << i << " " << sum << "\n";
23-
y++;
24-
}
25-
cout << "enter the x1->";
26-
cin >> x1;
27-
cout << "enter the no iteration to perform->\n";
28-
cin >> n;
8+
int main() {
9+
float y, x1, x2, x3, sum, s, a, f1, f2, gd;
10+
int i, n;
2911

30-
for (i = 0; i <= n; i++)
31-
{
32-
x2 = eqd(x1);
33-
cout << "\nenter the x2->" << x2;
34-
x1 = x2;
35-
}
36-
getch();
37-
}
12+
for (i = 0; i < 10; i++) {
13+
sum = eq(y);
14+
std::cout << "value of equation at " << i << " " << sum << "\n";
15+
y++;
16+
}
17+
std::cout << "enter the x1->";
18+
std::cin >> x1;
19+
std::cout << "enter the no iteration to perform->\n";
20+
std::cin >> n;
21+
22+
for (i = 0; i <= n; i++) {
23+
x2 = eqd(x1);
24+
std::cout << "\nenter the x2->" << x2;
25+
x1 = x2;
26+
}
27+
return 0;
28+
}

0 commit comments

Comments
 (0)