Problem As Matrices
Problem As Matrices
Problem As Matrices
#include <iostream>
#include <math.h>
using namespace std;
double det(double**, int);
int main()
{
int n; // n = numero de renglones = numero de columnas
double **m = NULL;
cout << "Orden de la matriz: ";cin >> n;
// Se crea la matriz de forma dinamica
m = (double **)malloc(sizeof(double)*n);
for (int i = 0; i<n; i++)
m[i] = (double *)malloc(sizeof(double)*n);
system("pause");
return 0;
}
double det(double **m, int b)
{
double determinante = 0, aux = 0;
int c;
if (b == 2)
return m[0][0] * m[1][1] - m[1][0] * m[0][1];
else{
for (int j = 0; j<b; j++){
double **menor = (double **)malloc(sizeof(double)*(b - 1
));
for (int h = 0; h<(b - 1); h++) menor[h] = (double *)mal
loc(sizeof(double)*(b - 1));
for (int k = 1; k<b; k++){
c = 0;
for (int l = 0; l<b; l++){
if (l != j){
menor[k - 1][c] = m[k][l];
c++;
}
}
}
aux = pow(-1, 2 + j)*m[0][j] * det(menor, b - 1);
determinante += aux;
for (int q = 0; q<(b - 1); q++)
free(menor[q]);
free(menor);
}
return determinante;
}
//Matriz de Vandermonde
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int i, j,det,p,k,t,orden;
long int A[100][100];
cout << "Orden de la matriz: "; cin >> orden;
for (int i = 0; i<orden; i++)
{
A[i][0] = 1;
}
cout << "\n";
for (int i = 0; i<orden; i++)
{
cout << "El numero A[" << i << "][1]:"; cin >> A[i][1];
}
for (int i = 0; i<orden; i++)
{
for (int j = 2; j<orden; j++)
{
A[i][j] = A[i][j - 1] * A[i][1];
}
}
cout << "\n";
cout << "Matriz de Vandermonde";
cout << "\n";
for (int i = 0; i<orden; i++)
{
for (int j = 0; j<orden; j++)
{
cout << setw(7) << A[i][j];
}
cout << "\n";
}
det= 1;
for (i = 0; i < orden; i++){
t = A[i][1];
k = i + 1;
if (k == orden){
break;
}
p = 1;
while (k < orden){
p = p*(A[k][1] - t);
k++;
}
det = det*p;
}
system("pause");
return 0;
}