void Observador::geraMatL(double b, double c) { geraMatQL( b, c); double **matTemp = Mat_Aloc(2,2); matTemp = Mat_Mult(matQL, 2, 2, matWoInv, 2, 2); matls = Mat_Mult(matTemp, 2, 2, matColSL, 2, 1); }
double Observador::calculaObservador(double tensao, double y, double polo1[2], double polo2[2]) { b = polo1[0]*2*(-1); c = polo1[0]*polo2[0] + polo1[1]*polo2[1]*-1; //qDebug() << "polos"; //qDebug() << polo1[0] << polo1[1]; //qDebug() << polo2[0] << polo2[1]; qDebug() << b << c; if(b != bold || c != cold) { // qDebug() << "#######################################!"; // qDebug() << "calculaObservador " << b << c; geraMatL2(b,c); //matL[0][0] = matls[0][0]; //matL[1][0] = matls[1][0]; qDebug() << "matQl"; qDebug() << matQL[0][0] << matQL[0][1]; qDebug() << matQL[1][0] << matQL[1][1]; qDebug() << "matL" << matL[0][0] << matL[1][0]; //qDebug() << "matls" << matls[0][0] << matls[1][0]; //qDebug() << "b c"; //qDebug() << b << c; //qDebug() << bold << cold; bold = b; cold = c; //bold = b; //cold = c; //qDebug() << bold << cold; // exit(-1); } matXObs = Mat_Sum(Mat_Mult(matG,2,2,matXObs,2,1), \ Mat_MultEscalar(matL, 2, 1, y-yObs), \ Mat_MultEscalar(matH, 2, 1, tensao), \ 2, 1); double **temp = Mat_Aloc(1,1); temp = Mat_Mult(matC,1,2, matXObs,2,1); yObs = temp[0][0]; erro = y - yObs; // qDebug() << "yObs " << yObs; Mat_Free(1,1,temp); return yObs; }
int main () { long double h = 0.2; long double k = 0.04; long double i; long double t; long double t_min = 0; long double t_max = 0.4; long double x_min = 0; long double x_max = 4.0; long double alpha = 4 / (LM_PI * LM_PI); long double lambda = alpha * (k / (h * h)); int j = (x_max - x_min) / h; int p = (t_max - t_min) / k; int d; long double xa = -lambda / 2.0; long double xb = 1 + lambda; long double xc = -xa; long double xd = 1 - lambda; matrix *A = NewMatrix (j, j); matrix *B = NewMatrix (j, j); matrix *w = NewMatrix (j, 1); for (d = 1; d <= j; d++) { Mat_SetCell (A, d, d - 1, xa); Mat_SetCell (A, d, d, xb); Mat_SetCell (A, d, d + 1, xa); Mat_SetCell (B, d, d - 1, xc); Mat_SetCell (B, d, d, xd); Mat_SetCell (B, d, d + 1, xc); Mat_SetCell (w, d, 1, f ((d) * h)); } printf ("A \n"); Mat_Print (A); printf ("B \n"); Mat_Print (B); matrix *Ai = Mat_FindInverse (A); printf ("Ai \n"); Mat_Print (Ai); matrix *Temp = Mat_Mult (Ai, B); matrix *w1; long double results[j + 1][p]; int q = 0; int s; int u; for (t = k; t <= t_max; t += k) { for (s = 0; s <= j; s++) results[s][q] = Mat_GetCell (w, s + 1, 1); q++; w1 = Mat_Mult (Temp, w); Mat_Dispose (w); w = w1; } for (s = 0; s <= j; s++) results[s][q] = Mat_GetCell (w, s + 1, 1); printf ("Estimated Answer:\n\n t "); for (t = t_min; t <= t_max; t += k) printf ("%8.5Lf ", t); printf ("\n"); printf ("i\n"); for (s = 0; s < j; s++) { printf ("%8.5Lf ", (s + 1) * h); for (u = 0; u <= p; u++) { printf ("%8.5Lf ", results[s][u]); } printf ("\n"); } printf ("\nExact Answer:\n\n t "); for (t = .4; t <= t_max; t += k) printf ("%8.5Lf ", t); printf ("\n"); printf ("i\n"); for (i = x_min + h; i < x_max; i += h) { printf ("%Lf ", i); for (t = .4; t <= t_max; t += k) { printf ("%8.5Lf ", powl (LM_E, -t) * sinl (LM_PI / 2.0 * i) + powl (LM_E, -t / 4.0) * sinl (LM_PI / 4.0 * i)); } printf ("\n"); } return 0; }