-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassignment.cpp
143 lines (132 loc) · 4.14 KB
/
assignment.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*Zunaied Nudar*/
/*Arpita Das*/
/*Anika Nawer*/
#include <bits/stdc++.h>
#include "jacobi_iterative.hpp"
#include "gauss_seidel_iterative.hpp"
#include "gauss_jordan_elimination.hpp"
#include "lu_factorization.hpp"
#include "bi_section.hpp"
#include "false_position.hpp"
#include "secant.hpp"
#include "newton_raphson.hpp"
#include "runge_kutta.hpp"
#include "matrix_inversion.hpp"
using namespace std;
void LE();
void NLE();
void MI();
int main() {
for (;;) {
cout << "Choose one of the following actions:\n\n";
cout << "1. Solve Linear Equations\n";
cout << "2. Solve Non-linear Equations\n";
cout << "3. Solve Differential Equations\n";
cout << "4. Matrix Inversion\n";
cout << "0. Exit\n\n";
cout << "Choice? ";
int choice;
cin >> choice;
switch (choice) {
case 1:
LE();
break;
case 2:
NLE();
break;
case 3:
DE();
break;
case 4:
MI();
break;
case 5:
exit(0);
default:
cout << "Invalid choice...\n";
}
}
return 0;
}
void LE() {
cout << "Enter the number of unknowns: ";
int unknowns;
cin >> unknowns;
int n = unknowns;
vector<vector<double>> coefficients(n, vector<double>(n + 1));
double error = 0.000001;
cout << "\nEnter all of the coefficients:\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < n + 1; j++) {
cin >> coefficients[i][j];
}
}
Linear* jacobiIterative = new JacobiIterative(unknowns, coefficients, error);
Linear* gaussSeidelIterative = new GaussSeidelIterative(unknowns, coefficients, error);
Linear* luFactorization = new LUFactorization(unknowns, coefficients, error);
/*Arpita Das*/
cout << "\nGauss Elimination:\n";
gauss_elimination(coefficients);
vector<vector<double>> result1 = gauss_eli(coefficients);
vector<vector<double>> result2 = gauss_jordan(result1);
cout << "\nGauss-Jordan Elimination:\n";
vector<vector<double>> result3 = rref(result2);
int r = result3.size();
int c = result3[0].size();
for (int i = 0; i < r; i++) {
cout << result3[i][c - 1] << " ";
}
cout << "\n";
cout << "\nJacobi Iterative:\n";
jacobiIterative->calculate();
cout << "\nGauss-Seidel Iterative:\n";
gaussSeidelIterative->calculate();
cout << "\nLU Factorization:\n";
luFactorization->calculate();
cout << "\n\n\n";
}
void NLE() {
cout << setprecision(3) << fixed;
cout << "Enter the degree of polynomial: ";
int degree;
cin >> degree;
int n = degree;
vector<int> coefficients(n + 1);
double error = 0.000001;
cout << "\nEnter all of the coefficients:\n";
for (int i = 0; i < n + 1; i++) {
cin >> coefficients[i];
}
NonLinear* biSection = new BiSection(degree, coefficients, error);
NonLinear* falsePosition = new FalsePosition(degree, coefficients, error);
NonLinear* secant = new Secant(degree, coefficients, error);
NonLinear* newtonRaphson = new NewtonRaphson(degree, coefficients, error);
cout << "\nBi-Section:\n";
biSection->calculate();
cout << "\nFalse Position:\n";
falsePosition->calculate();
cout << "\nSecant:\n";
secant->calculate();
cout << "\nNewton-Raphson:\n";
newtonRaphson->calculate();
cout << "\n\n\n";
}
void MI() {
cout << "Enter the order of the matrix: ";
int order;
cin >> order;
vector<vector<double>> matrix(order, vector<double>(order));
cout << "\nEnter all of the elements:\n";
for (int i = 0; i < order; i++) {
for (int j = 0; j < order; j++) {
cin >> matrix[i][j];
}
}
Linear* matrixInversion = new MatrixInversion(matrix);
cout << "\nMatrix Inversion:\n";
matrixInversion->calculate();
cout << "\n\n\n";
}
/*Zunaied Nudar*/
/*Arpita Das*/
/*Anika Nawer*/