-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatriz.c
81 lines (66 loc) · 1.22 KB
/
Matriz.c
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
#include <stdio.h>
#include <stdlib.h>
#include "Matriz.h"
#include <math.h>
double* vetcria (int n){
double *vet;
vet = (double *)malloc(n*sizeof(double));
return vet;
}
void vetlibera (double* v){
free(v);
}
double escalar(int n, double *vet1, double *vet2){
double *vetProd = (double *)malloc(n*sizeof(double));
double soma = 0;
int i;
for(i = 0; i < n; i++){
vetProd[i] = vet1[i] * vet2[i];
soma += vetProd[i];
}
return soma;
}
double norma2 (int n, double* v){
int i;
double soma = 0;
for (i=0; i<n; i++){
v[i] = pow(v[i],2);
soma += v[i];
}
soma = sqrt(soma);
return soma;
}
double** matcria (int m, int n){
int i;
double **Mat;
Mat = (double **)malloc(m*sizeof(double));
for(i=0; i<m; i++){
Mat[i] = vetcria(n);
}
return Mat;
}
void matlibera (int m, double** A){
int i;
for(i=0; i<m;i++){
vetlibera(A[i]);
}
free(A);
}
void transposta (int m, int n, double** A, double** T){ //m = linha;;;n = coluna
int i, aux, aux2,j;
for(i=0; i<m; i++){
aux = i;
for(j=0; j<n ; j++){
aux2 = j;
T[aux2][aux] = A[aux][aux2];
}
}
}
void multmv (int m, int n, double** A, double* v, double* w){
int i,j;
for(i=0; i<m; i++){
for(j=0; j<n; j++){
w[j] = A[i][j] * v[j];
}
}
}