online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <iomanip> #include <math.h> using namespace std; int main() { // Define the matrix. double A[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; // Find the eigenvalues and eigenvectors. double eigenvalues[3]; double eigenvectors[3][3]; bool foundEigenvectors = false; for (int i = 0; i < 3; i++) { double a = A[i][i] - eigenvalues[0]; double b = A[i][i] - eigenvalues[1]; double c = A[i][i] - eigenvalues[2]; double d = A[i][0] + A[i][1] + A[i][2]; double e = A[0][0] * A[1][1] + A[0][0] * A[2][2] + A[1][1] * A[2][2] - A[0][1] * A[0][1] - A[0][2] * A[0][2] - A[1][2] * A[1][2]; double det = a * b * c - d * e; if (det != 0) { eigenvalues[i] = det / (a * b - d * c); double x1 = (b * e - d * c) / (a * b - d * c); double x2 = (a * e - d * b) / (a * b - d * c); eigenvectors[i][0] = x1; eigenvectors[i][1] = x2; eigenvectors[i][2] = 1 - x1 - x2; foundEigenvectors = true; } } // Print the eigenvalues and eigenvectors. if (foundEigenvectors) { cout << "Eigenvalues: " << endl; for (int i = 0; i < 3; i++) { cout << eigenvalues[i] << " "; } cout << endl; cout << "Eigenvectors: " << endl; for (int i = 0; i < 3; i++) { cout << setprecision(3) << eigenvectors[i][0] << " " << eigenvectors[i][1] << " " << eigenvectors[i][2] << endl; } } else { cout << "No eigenvalues found." << endl; } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue