Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "rt_nonfinite.h"
00012 #include "Optimal_affine_tracking_3d16_fast_realtime.h"
00013 #include "mrdivide.h"
00014 #include "mldivide.h"
00015 #include "expm.h"
00016 #include "Optimal_affine_tracking_3d16_fast_realtime_rtwutil.h"
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 static real_T b_eml_xnrm2(int32_T n, const real_T x[12], int32_T ix0);
00028 static real_T eml_xnrm2(int32_T n, const real_T x[12], int32_T ix0);
00029
00030
00031 static real_T b_eml_xnrm2(int32_T n, const real_T x[12], int32_T ix0)
00032 {
00033 real_T y;
00034 real_T scale;
00035 int32_T kend;
00036 int32_T k;
00037 real_T absxk;
00038 real_T t;
00039 y = 0.0;
00040 if (n == 1) {
00041 y = fabs(x[ix0 - 1]);
00042 } else {
00043 scale = 2.2250738585072014E-308;
00044 kend = (ix0 + n) - 1;
00045 for (k = ix0; k <= kend; k++) {
00046 absxk = fabs(x[k - 1]);
00047 if (absxk > scale) {
00048 t = scale / absxk;
00049 y = 1.0 + y * t * t;
00050 scale = absxk;
00051 } else {
00052 t = absxk / scale;
00053 y += t * t;
00054 }
00055 }
00056
00057 y = scale * sqrt(y);
00058 }
00059
00060 return y;
00061 }
00062
00063 static real_T eml_xnrm2(int32_T n, const real_T x[12], int32_T ix0)
00064 {
00065 real_T y;
00066 real_T scale;
00067 int32_T kend;
00068 int32_T k;
00069 real_T absxk;
00070 real_T t;
00071 y = 0.0;
00072 if (n == 1) {
00073 y = fabs(x[ix0 - 1]);
00074 } else {
00075 scale = 2.2250738585072014E-308;
00076 kend = (ix0 + n) - 1;
00077 for (k = ix0; k <= kend; k++) {
00078 absxk = fabs(x[k - 1]);
00079 if (absxk > scale) {
00080 t = scale / absxk;
00081 y = 1.0 + y * t * t;
00082 scale = absxk;
00083 } else {
00084 t = absxk / scale;
00085 y += t * t;
00086 }
00087 }
00088
00089 y = scale * sqrt(y);
00090 }
00091
00092 return y;
00093 }
00094
00095 void b_mrdivide(const creal_T A[4], const creal_T B[4], creal_T y[4])
00096 {
00097 creal_T b_A[4];
00098 creal_T b_B[4];
00099 int32_T r1;
00100 int32_T r2;
00101 creal_T a21;
00102 creal_T a22;
00103 creal_T Y[4];
00104 int32_T k;
00105 creal_T c_B;
00106 for (r1 = 0; r1 < 2; r1++) {
00107 for (r2 = 0; r2 < 2; r2++) {
00108 b_A[r2 + (r1 << 1)].re = B[r1 + (r2 << 1)].re;
00109 b_A[r2 + (r1 << 1)].im = -B[r1 + (r2 << 1)].im;
00110 b_B[r2 + (r1 << 1)].re = A[r1 + (r2 << 1)].re;
00111 b_B[r2 + (r1 << 1)].im = -A[r1 + (r2 << 1)].im;
00112 }
00113 }
00114
00115 if (fabs(b_A[1].re) + fabs(b_A[1].im) > fabs(b_A[0].re) + fabs(b_A[0].im)) {
00116 r1 = 1;
00117 r2 = 0;
00118 } else {
00119 r1 = 0;
00120 r2 = 1;
00121 }
00122
00123 a21 = c_eml_div(b_A[r2], b_A[r1]);
00124 a22.re = b_A[2 + r2].re - (a21.re * b_A[2 + r1].re - a21.im * b_A[2 + r1].im);
00125 a22.im = b_A[2 + r2].im - (a21.re * b_A[2 + r1].im + a21.im * b_A[2 + r1].re);
00126 for (k = 0; k < 2; k++) {
00127 c_B.re = b_B[r2 + (k << 1)].re - (b_B[r1 + (k << 1)].re * a21.re - b_B[r1 +
00128 (k << 1)].im * a21.im);
00129 c_B.im = b_B[r2 + (k << 1)].im - (b_B[r1 + (k << 1)].re * a21.im + b_B[r1 +
00130 (k << 1)].im * a21.re);
00131 Y[1 + (k << 1)] = c_eml_div(c_B, a22);
00132 c_B.re = b_B[r1 + (k << 1)].re - (Y[1 + (k << 1)].re * b_A[2 + r1].re - Y[1
00133 + (k << 1)].im * b_A[2 + r1].im);
00134 c_B.im = b_B[r1 + (k << 1)].im - (Y[1 + (k << 1)].re * b_A[2 + r1].im + Y[1
00135 + (k << 1)].im * b_A[2 + r1].re);
00136 Y[k << 1] = c_eml_div(c_B, b_A[r1]);
00137 }
00138
00139 for (r1 = 0; r1 < 2; r1++) {
00140 for (r2 = 0; r2 < 2; r2++) {
00141 y[r2 + (r1 << 1)].re = Y[r1 + (r2 << 1)].re;
00142 y[r2 + (r1 << 1)].im = -Y[r1 + (r2 << 1)].im;
00143 }
00144 }
00145 }
00146
00147 void mrdivide(const real_T A[12], const real_T B[12], real_T y[9])
00148 {
00149 real_T tau[3];
00150 real_T b_A[12];
00151 real_T b_B[12];
00152 int8_T jpvt[3];
00153 real_T work[3];
00154 int32_T i4;
00155 int32_T nmip1;
00156 real_T vn1[3];
00157 real_T vn2[3];
00158 int32_T k;
00159 int32_T j;
00160 real_T b_y;
00161 real_T wj;
00162 real_T rankR;
00163 real_T t;
00164 int32_T i;
00165 int32_T i_i;
00166 int32_T pvt;
00167 int32_T ix;
00168 int32_T iy;
00169 int32_T i_ip1;
00170 int32_T lastv;
00171 boolean_T exitg2;
00172 int32_T exitg1;
00173 real_T Y[9];
00174 for (i4 = 0; i4 < 3; i4++) {
00175 for (nmip1 = 0; nmip1 < 4; nmip1++) {
00176 b_A[nmip1 + (i4 << 2)] = B[i4 + 3 * nmip1];
00177 b_B[nmip1 + (i4 << 2)] = A[i4 + 3 * nmip1];
00178 }
00179
00180 jpvt[i4] = (int8_T)(1 + i4);
00181 work[i4] = 0.0;
00182 }
00183
00184 k = 1;
00185 for (j = 0; j < 3; j++) {
00186 b_y = 0.0;
00187 wj = 2.2250738585072014E-308;
00188 for (nmip1 = k; nmip1 <= k + 3; nmip1++) {
00189 rankR = fabs(b_A[nmip1 - 1]);
00190 if (rankR > wj) {
00191 t = wj / rankR;
00192 b_y = 1.0 + b_y * t * t;
00193 wj = rankR;
00194 } else {
00195 t = rankR / wj;
00196 b_y += t * t;
00197 }
00198 }
00199
00200 b_y = wj * sqrt(b_y);
00201 vn1[j] = b_y;
00202 vn2[j] = vn1[j];
00203 k += 4;
00204 }
00205
00206 for (i = 0; i < 3; i++) {
00207 i_i = i + (i << 2);
00208 nmip1 = 3 - i;
00209 pvt = 0;
00210 if (nmip1 > 1) {
00211 ix = i;
00212 wj = fabs(vn1[i]);
00213 for (k = 2; k <= nmip1; k++) {
00214 ix++;
00215 rankR = fabs(vn1[ix]);
00216 if (rankR > wj) {
00217 pvt = k - 1;
00218 wj = rankR;
00219 }
00220 }
00221 }
00222
00223 pvt += i;
00224 if (pvt + 1 != i + 1) {
00225 ix = pvt << 2;
00226 iy = i << 2;
00227 for (k = 0; k < 4; k++) {
00228 wj = b_A[ix];
00229 b_A[ix] = b_A[iy];
00230 b_A[iy] = wj;
00231 ix++;
00232 iy++;
00233 }
00234
00235 nmip1 = jpvt[pvt];
00236 jpvt[pvt] = jpvt[i];
00237 jpvt[i] = (int8_T)nmip1;
00238 vn1[pvt] = vn1[i];
00239 vn2[pvt] = vn2[i];
00240 }
00241
00242 nmip1 = i_i + 2;
00243 t = b_A[i_i];
00244 rankR = 0.0;
00245 wj = eml_xnrm2(3 - i, b_A, nmip1);
00246 if (wj != 0.0) {
00247 wj = rt_hypotd_snf(fabs(b_A[i_i]), fabs(wj));
00248 if (b_A[i_i] >= 0.0) {
00249 wj = -wj;
00250 }
00251
00252 if (fabs(wj) < 1.0020841800044864E-292) {
00253 pvt = 0;
00254 do {
00255 pvt++;
00256 i4 = (nmip1 - i) + 2;
00257 for (k = nmip1; k <= i4; k++) {
00258 b_A[k - 1] *= 9.9792015476736E+291;
00259 }
00260
00261 wj *= 9.9792015476736E+291;
00262 t *= 9.9792015476736E+291;
00263 } while (!(fabs(wj) >= 1.0020841800044864E-292));
00264
00265 wj = rt_hypotd_snf(fabs(t), fabs(eml_xnrm2(3 - i, b_A, nmip1)));
00266 if (t >= 0.0) {
00267 wj = -wj;
00268 }
00269
00270 rankR = (wj - t) / wj;
00271 t = 1.0 / (t - wj);
00272 i4 = (nmip1 - i) + 2;
00273 while (nmip1 <= i4) {
00274 b_A[nmip1 - 1] *= t;
00275 nmip1++;
00276 }
00277
00278 for (k = 1; k <= pvt; k++) {
00279 wj *= 1.0020841800044864E-292;
00280 }
00281
00282 t = wj;
00283 } else {
00284 rankR = (wj - b_A[i_i]) / wj;
00285 t = 1.0 / (b_A[i_i] - wj);
00286 i4 = (nmip1 - i) + 2;
00287 while (nmip1 <= i4) {
00288 b_A[nmip1 - 1] *= t;
00289 nmip1++;
00290 }
00291
00292 t = wj;
00293 }
00294 }
00295
00296 tau[i] = rankR;
00297 b_A[i_i] = t;
00298 if (i + 1 < 3) {
00299 t = b_A[i_i];
00300 b_A[i_i] = 1.0;
00301 i_ip1 = (i + ((i + 1) << 2)) + 1;
00302 if (tau[i] != 0.0) {
00303 lastv = 3 - i;
00304 nmip1 = (i_i - i) + 3;
00305 while ((lastv + 1 > 0) && (b_A[nmip1] == 0.0)) {
00306 lastv--;
00307 nmip1--;
00308 }
00309
00310 k = 2 - i;
00311 exitg2 = FALSE;
00312 while ((exitg2 == 0U) && (k > 0)) {
00313 nmip1 = i_ip1 + ((k - 1) << 2);
00314 j = nmip1;
00315 do {
00316 exitg1 = 0;
00317 if (j <= nmip1 + lastv) {
00318 if (b_A[j - 1] != 0.0) {
00319 exitg1 = 1;
00320 } else {
00321 j++;
00322 }
00323 } else {
00324 k--;
00325 exitg1 = 2;
00326 }
00327 } while (exitg1 == 0U);
00328
00329 if (exitg1 == 1U) {
00330 exitg2 = TRUE;
00331 }
00332 }
00333 } else {
00334 lastv = -1;
00335 k = 0;
00336 }
00337
00338 if (lastv + 1 > 0) {
00339 if (k == 0) {
00340 } else {
00341 nmip1 = k - 1;
00342 for (iy = 1; iy <= nmip1 + 1; iy++) {
00343 work[iy - 1] = 0.0;
00344 }
00345
00346 iy = 0;
00347 i4 = i_ip1 + (nmip1 << 2);
00348 for (pvt = i_ip1; pvt <= i4; pvt += 4) {
00349 ix = i_i;
00350 wj = 0.0;
00351 nmip1 = (pvt + lastv) + 1;
00352 for (j = pvt; j <= nmip1 - 1; j++) {
00353 wj += b_A[j - 1] * b_A[ix];
00354 ix++;
00355 }
00356
00357 work[iy] += wj;
00358 iy++;
00359 }
00360 }
00361
00362 if (-tau[i] == 0.0) {
00363 } else {
00364 nmip1 = 0;
00365 for (j = 1; j <= k; j++) {
00366 if (work[nmip1] != 0.0) {
00367 wj = work[nmip1] * -tau[i];
00368 ix = i_i;
00369 i4 = lastv + i_ip1;
00370 for (pvt = i_ip1; pvt <= i4; pvt++) {
00371 b_A[pvt - 1] += b_A[ix] * wj;
00372 ix++;
00373 }
00374 }
00375
00376 nmip1++;
00377 i_ip1 += 4;
00378 }
00379 }
00380 }
00381
00382 b_A[i_i] = t;
00383 }
00384
00385 for (j = i + 1; j + 1 < 4; j++) {
00386 if (vn1[j] != 0.0) {
00387 rankR = fabs(b_A[i + (j << 2)]) / vn1[j];
00388 b_y = rankR * rankR;
00389 rankR = 1.0 - rankR * rankR;
00390 if (1.0 - b_y < 0.0) {
00391 rankR = 0.0;
00392 }
00393
00394 wj = vn1[j] / vn2[j];
00395 if (rankR * (wj * wj) <= 1.4901161193847656E-8) {
00396 vn1[j] = b_eml_xnrm2(3 - i, b_A, (i + (j << 2)) + 2);
00397 vn2[j] = vn1[j];
00398 } else {
00399 vn1[j] *= sqrt(rankR);
00400 }
00401 }
00402 }
00403 }
00404
00405 rankR = 0.0;
00406 k = 0;
00407 while ((k < 3) && (!(fabs(b_A[k + (k << 2)]) <= 4.0 * fabs(b_A[0]) *
00408 2.2204460492503131E-16))) {
00409 rankR++;
00410 k++;
00411 }
00412
00413 memset(&Y[0], 0, 9U * sizeof(real_T));
00414 for (j = 0; j < 3; j++) {
00415 if (tau[j] != 0.0) {
00416 for (k = 0; k < 3; k++) {
00417 wj = b_B[j + (k << 2)];
00418 for (i = 0; i <= 2 - j; i++) {
00419 nmip1 = (j + i) + 1;
00420 wj += b_A[nmip1 + (j << 2)] * b_B[nmip1 + (k << 2)];
00421 }
00422
00423 wj *= tau[j];
00424 if (wj != 0.0) {
00425 b_B[j + (k << 2)] -= wj;
00426 for (i = 0; i <= 2 - j; i++) {
00427 nmip1 = (j + i) + 1;
00428 b_B[nmip1 + (k << 2)] -= b_A[nmip1 + (j << 2)] * wj;
00429 }
00430 }
00431 }
00432 }
00433 }
00434
00435 for (k = 0; k < 3; k++) {
00436 for (i = 0; i <= (int32_T)rankR - 1; i++) {
00437 Y[(jpvt[i] + 3 * k) - 1] = b_B[i + (k << 2)];
00438 }
00439
00440 for (j = 0; j <= (int32_T)-(1.0 + (-1.0 - rankR)) - 1; j++) {
00441 wj = rankR + -(real_T)j;
00442 Y[(jpvt[(int32_T)wj - 1] + 3 * k) - 1] /= b_A[((int32_T)wj + (((int32_T)wj
00443 - 1) << 2)) - 1];
00444 for (i = 0; i <= (int32_T)wj - 2; i++) {
00445 Y[(jpvt[i] + 3 * k) - 1] -= Y[(jpvt[(int32_T)wj - 1] + 3 * k) - 1] *
00446 b_A[i + (((int32_T)wj - 1) << 2)];
00447 }
00448 }
00449 }
00450
00451 for (i4 = 0; i4 < 3; i4++) {
00452 for (nmip1 = 0; nmip1 < 3; nmip1++) {
00453 y[nmip1 + 3 * i4] = Y[i4 + 3 * nmip1];
00454 }
00455 }
00456 }
00457
00458