Kör denna kod.
Kod: Markera allt
#include <stdio.h>
#include <stdlib.h>
#include "LinearAlgebra/declareFunctions.h"
int main() {
/*
* G(s) = 4/(2s^2 + s + 5) - Model
*/
float input[72] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
float output[72] = {0.00000, 3.47145, 6.41826, 4.35654, 2.53855, 3.76202, 4.88287, 4.15747, 3.46685, 3.89656, 4.32183,
4.06753, 3.80580, 3.95616, 4.11713, 4.02833, 3.92938, 3.98176, 4.04256, 4.01169, 3.97436, 3.99253,
4.01544, 4.00476, 3.99070, 3.99697, 4.00559, 4.00192, 3.99664, 3.99879, 4.00202, 4.00077, 3.99878,
3.99952, 4.00073, 4.00030, 3.99956, 3.99981, 4.00026, 4.00012, 3.99984, 3.99993, 4.00009, 4.00005,
3.99994, 3.99997, 4.00003, 4.00002, 3.99998, 3.99999, 4.00001, 4.00001, 3.99999, 4.00000, 4.00000,
4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000,
4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000};
// Create toeplitz matrix
matrix* toe = toeplitz(input, 72);
// Create upper triangular matrix of the toeplitz matrix
matrix* tru = triu(toe, 0);
// Find the inverse of tru
matrix* iv = inv(tru);
// Create vector the horizon - Important! Else, we cannot find the markov-parameters g
matrix* Y = create(output, 1, 72);
// Multiply Y with the iv matrix - Find the markov-parameters g
matrix* G = mul(Y, iv, false);
// Detete some mats
freeMatrix(toe);
freeMatrix(tru);
freeMatrix(iv);
freeMatrix(Y);
/*--------------------------------------*/
// turn vector G into a normal vector because the function hankel only want 1D vector
float g[72];
for(int i = 0; i < 72; i++)
g[i] = *(G->data + i);
// Delete G
freeMatrix(G);
// Create hankel matrix H0 and H1
matrix* H0 = hankel(g, 72, 1);
matrix* H1 = hankel(g, 72, 2);
// Cut H1 and H2 to the half - Remember indexing from zero here!
matrix* H0_half = cut(H0, 0, 35, 0, 35); // 36x36 from 72x72
// Remove H0
freeMatrix(H0);
// Measure the size
/*
int n;
int m;
size(H0_half, &n, &m);
printf("The H0_half have the size %dx%d\n\n,", n, m);
*/
// Do SVD on
matrix* u = initMatrix(36,36); // We know the size from the size() command above
matrix* s = initMatrix(36,36);
matrix* v = initMatrix(36,36);
svd(H0_half, u, s, v);
freeMatrix(H0_half);
printMatrix(s);
/*
matrix* E = initMatrix(36,36);
int n = E->row;
int m = E->column;
float* e_ptr = E->data;
float* s_ptr = s->data;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(j == i){
*((e_ptr + i*n + j)) = 1/sqrt(*(s_ptr + i*n + j));
}
}
}
//printMatrix(s);
*/
return EXIT_SUCCESS;
}
Dom första s-värderna stämmer riktigt bra med mitt C-bibliotek, men övrigt så stämmer det inte alls. Boven i dramat är qr.c filen. Men den fungerar ändå för andra typer av värden.