void MatrSolver::Solve(){ det = Det(matr, n); std::cout << "Определитель матрицы = " << det << std::endl; if (det) FindObrMatr(); else std::cout << "Т.к. определитель матрицы = 0,\nто матрица вырожденная и обратной не имеет!!!" << std::endl; TransponMtx(obr_matr, tobr_matr, n); PrintMtx(tobr_matr, n); SolveEquation(tobr_matr, b_matr, res, n); std::cout << "Результат: " << std::endl; PrintVector(res, n); FreeResources(); }
NX::vector<float, 3> Triangle::GetBaryCentricCoord(const NX::vector<float, 3> &point) const{ const NX::vector<float, 3> e1(m_vPtA - m_vPtC); const NX::vector<float, 3> e2(m_vPtB - m_vPtC); const NX::vector<float, 3> r(point - m_vPtC); NX::Matrix<float, 2, 2> m; NX::vector<float, 2> result; { m[0][0] = NX::Dot(e1, e1), m[0][1] = NX::Dot(e1, e2), result[0] = NX::Dot(r, e1); m[1][0] = m[0][1], m[1][1] = NX::Dot(e2, e2), result[1] = NX::Dot(r, e2); } const std::pair<bool, NX::vector<float, 2> > solv = SolveEquation(m, result); return NX::vector<float, 3>(solv.second.x, solv.second.y, 1.0f - solv.second.x - solv.second.y); }
ForwardEulerSolver::ForwardEulerSolver(int N, double startTime, double endTime, double initialValue){ if (endTime > startTime){ if (N > 1){ SetIterationNumber(N); SetInitialValue(initialValue); SetTimeInterval(startTime, endTime); SetStepSize((endTime - startTime)/(N - 1)); double* output = SolveEquation(); for (int i = 0; i < GetIterationNumber(); ++i) { std::cout << output[i] << " " << GetInitialTime() + i*GetStepSize() << " " << test(GetInitialTime() + i*GetStepSize())<< "\n"; } } else{ std::cerr << "The number of iterations needs to be > 1!!\n"; } } else{ std::cerr << "Final time needs to be after initial!!\n"; } }
int main (int argc, char *argv[]) { double a, b, c, x1, x2; printf ("Введите коэффициенты квадратичного уравнения (a, b, c): "); scanf ("%lf %lf %lf", &a, &b, &c); switch (SolveEquation (a, b, c, &x1, &x2)) { case NO_ROOT: printf ("\tУравнение не имеет корней\n"); break; case ONE_ROOT: printf ("\tНайден один корень: x = %lf\n", x1); break; case TWO_ROOTS: printf ("\tНайдены два корня: x1 = %lf и x2 = %lf\n", x1, x2); break; case ENDLESS_ROOTS: printf ("\nУравнение имеет бесконечное множество корней\n"); break; } return 0; }