Пример #1
0
/* Function Definitions */
void b_exp(const emlrtStack *sp, emxArray_real_T *x)
{
  int32_T nx;
  boolean_T overflow;
  int32_T k;
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &y_emlrtRSI;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  nx = x->size[0];
  b_st.site = &ab_emlrtRSI;
  if (1 > x->size[0]) {
    overflow = false;
  } else {
    overflow = (x->size[0] > 2147483646);
  }

  if (overflow) {
    c_st.site = &k_emlrtRSI;
    check_forloop_overflow_error(&c_st);
  }

  for (k = 0; k + 1 <= nx; k++) {
    x->data[k] = muDoubleScalarExp(x->data[k]);
  }
}
Пример #2
0
/* Function Definitions */
void b_exp(emxArray_real_T *x)
{
  int32_T i2;
  int32_T k;
  i2 = x->size[1];
  for (k = 0; k < i2; k++) {
    x->data[k] = muDoubleScalarExp(x->data[k]);
  }
}
Пример #3
0
/* Function Definitions */
void b_exp(creal_T x_data[1280], int32_T x_size[1])
{
  int32_T i32;
  int32_T k;
  real_T r;
  real_T x_data_im;
  real_T b_x_data_im;
  i32 = x_size[0];
  for (k = 0; k < i32; k++) {
    r = muDoubleScalarExp(x_data[k].re / 2.0);
    x_data_im = x_data[k].im;
    b_x_data_im = x_data[k].im;
    x_data[k].re = r * (r * muDoubleScalarCos(x_data_im));
    x_data[k].im = r * (r * muDoubleScalarSin(b_x_data_im));
  }
}
Пример #4
0
static void c9_chartstep_c9_Array(SFc9_ArrayInstanceStruct *chartInstance)
{
  real_T c9_hoistedGlobal;
  real_T c9_b_hoistedGlobal;
  real_T c9_c_hoistedGlobal;
  real_T c9_V;
  real_T c9_Radiacion;
  real_T c9_Temp;
  uint32_T c9_debug_family_var_map[23];
  real_T c9_q;
  real_T c9_K;
  real_T c9_n;
  real_T c9_T;
  real_T c9_Rs;
  real_T c9_Rp;
  real_T c9_Vt;
  real_T c9_Ns;
  real_T c9_Vc;
  real_T c9_Isc;
  real_T c9_Alfa;
  real_T c9_Iph;
  real_T c9_Voc_ref;
  real_T c9_Beta;
  real_T c9_Voc;
  real_T c9_Io;
  real_T c9_Ir;
  real_T c9_nargin = 3.0;
  real_T c9_nargout = 1.0;
  real_T c9_I;
  real_T c9_b;
  real_T c9_y;
  real_T c9_A;
  real_T c9_x;
  real_T c9_b_x;
  real_T c9_c_x;
  real_T c9_d_x;
  real_T c9_b_b;
  real_T c9_b_y;
  real_T c9_b_A;
  real_T c9_e_x;
  real_T c9_f_x;
  real_T c9_c_y;
  real_T c9_c_b;
  real_T c9_d_y;
  real_T c9_a;
  real_T c9_d_b;
  real_T c9_e_b;
  real_T c9_e_y;
  real_T c9_f_b;
  real_T c9_c_A;
  real_T c9_B;
  real_T c9_g_x;
  real_T c9_f_y;
  real_T c9_h_x;
  real_T c9_g_y;
  real_T c9_h_y;
  real_T c9_i_x;
  real_T c9_j_x;
  real_T c9_b_B;
  real_T c9_i_y;
  real_T c9_j_y;
  int32_T c9_i;
  real_T c9_k_x;
  real_T c9_k_y;
  real_T c9_l_x;
  real_T c9_l_y;
  real_T c9_z;
  real_T c9_m_x;
  real_T c9_n_x;
  real_T c9_d_A;
  real_T c9_o_x;
  real_T c9_p_x;
  real_T c9_m_y;
  real_T c9_n_y;
  real_T c9_o_y;
  real_T c9_b_z;
  real_T c9_b_a;
  real_T c9_g_b;
  real_T c9_p_y;
  real_T c9_q_x;
  real_T c9_q_y;
  real_T c9_r_x;
  real_T c9_r_y;
  real_T c9_c_z;
  real_T c9_s_x;
  real_T c9_t_x;
  real_T c9_u_x;
  real_T c9_s_y;
  real_T c9_v_x;
  real_T c9_t_y;
  real_T c9_d_z;
  real_T *c9_b_Temp;
  real_T *c9_b_Radiacion;
  real_T *c9_b_V;
  real_T *c9_b_I;
  c9_b_Temp = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
  c9_b_Radiacion = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
  c9_b_I = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c9_b_V = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 8U, chartInstance->c9_sfEvent);
  c9_hoistedGlobal = *c9_b_V;
  c9_b_hoistedGlobal = *c9_b_Radiacion;
  c9_c_hoistedGlobal = *c9_b_Temp;
  c9_V = c9_hoistedGlobal;
  c9_Radiacion = c9_b_hoistedGlobal;
  c9_Temp = c9_c_hoistedGlobal;
  sf_debug_symbol_scope_push_eml(0U, 23U, 23U, c9_debug_family_names,
    c9_debug_family_var_map);
  sf_debug_symbol_scope_add_eml(&c9_q, 0U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c9_K, 1U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c9_n, 2U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c9_T, 3U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c9_Rs, 4U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c9_Rp, 5U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c9_Vt, 6U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c9_Ns, 7U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c9_Vc, 8U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c9_Isc, 9U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c9_Alfa, 10U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c9_Iph, 11U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c9_Voc_ref, 12U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c9_Beta, 13U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c9_Voc, 14U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c9_Io, 15U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c9_Ir, 16U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c9_nargin, 17U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c9_nargout, 18U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c9_V, 19U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c9_Radiacion, 20U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c9_Temp, 21U, c9_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c9_I, 22U, c9_sf_marshallOut,
    c9_sf_marshallIn);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 3);
  c9_q = 1.602176E-19;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 5);
  c9_K = 1.3806488E-23;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 7);
  c9_n = 1.3;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 9);
  c9_T = 273.15 + c9_Temp;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 11);
  c9_Rs = 0.015;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 13);
  c9_Rp = 100.0;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 15);
  c9_b = c9_T;
  c9_y = 1.79484344E-23 * c9_b;
  c9_A = c9_y;
  c9_x = c9_A;
  c9_b_x = c9_x;
  c9_Vt = c9_b_x / 1.602176E-19;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 16);
  c9_Ns = 36.0;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 17);
  c9_c_x = c9_V;
  c9_d_x = c9_c_x;
  c9_Vc = c9_d_x / 36.0;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 19);
  c9_Isc = 5.433;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 20);
  c9_Alfa = 0.00037;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 22);
  c9_b_b = c9_Radiacion;
  c9_b_y = 5.433 * c9_b_b;
  c9_b_A = c9_b_y;
  c9_e_x = c9_b_A;
  c9_f_x = c9_e_x;
  c9_c_y = c9_f_x / 1000.0;
  c9_c_b = c9_Temp - 25.0;
  c9_d_y = 0.00037 * c9_c_b;
  c9_a = c9_c_y;
  c9_d_b = 1.0 + c9_d_y;
  c9_Iph = c9_a * c9_d_b;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 24);
  c9_Voc_ref = 0.6166666666666667;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 25);
  c9_Beta = -0.0034000000000000002;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 26);
  c9_e_b = c9_Temp - 25.0;
  c9_e_y = -0.0034000000000000002 * c9_e_b;
  c9_f_b = 1.0 + c9_e_y;
  c9_Voc = 0.6166666666666667 * c9_f_b;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 32);
  c9_c_A = c9_Voc;
  c9_B = c9_Vt;
  c9_g_x = c9_c_A;
  c9_f_y = c9_B;
  c9_h_x = c9_g_x;
  c9_g_y = c9_f_y;
  c9_h_y = c9_h_x / c9_g_y;
  c9_i_x = c9_h_y;
  c9_j_x = c9_i_x;
  c9_j_x = muDoubleScalarExp(c9_j_x);
  c9_b_B = c9_j_x - 1.0;
  c9_i_y = c9_b_B;
  c9_j_y = c9_i_y;
  c9_Io = 5.433 / c9_j_y;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 33);
  c9_Ir = c9_Io;
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 36);
  c9_I = 0.0;
  c9_i = 0;
  while (c9_i < 50) {
    CV_EML_FOR(0, 1, 0, 1);
    _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, 38);
    c9_k_x = c9_Vc + c9_I * c9_Rs;
    c9_k_y = c9_Vt;
    c9_l_x = c9_k_x;
    c9_l_y = c9_k_y;
    c9_z = c9_l_x / c9_l_y;
    c9_m_x = c9_z;
    c9_n_x = c9_m_x;
    c9_n_x = muDoubleScalarExp(c9_n_x);
    c9_d_A = c9_Vc + c9_I * c9_Rs;
    c9_o_x = c9_d_A;
    c9_p_x = c9_o_x;
    c9_m_y = c9_p_x / 100.0;
    c9_n_y = c9_Vt;
    c9_o_y = c9_n_y;
    c9_b_z = 0.015 / c9_o_y;
    c9_b_a = c9_Ir;
    c9_g_b = c9_b_z;
    c9_p_y = c9_b_a * c9_g_b;
    c9_q_x = c9_Vc + c9_I * c9_Rs;
    c9_q_y = c9_Vt;
    c9_r_x = c9_q_x;
    c9_r_y = c9_q_y;
    c9_c_z = c9_r_x / c9_r_y;
    c9_s_x = c9_c_z;
    c9_t_x = c9_s_x;
    c9_t_x = muDoubleScalarExp(c9_t_x);
    c9_u_x = ((c9_Iph - c9_I) - c9_Ir * (c9_n_x - 1.0)) + c9_m_y;
    c9_s_y = (-1.0 - c9_p_y * c9_t_x) - 0.00015;
    c9_v_x = c9_u_x;
    c9_t_y = c9_s_y;
    c9_d_z = c9_v_x / c9_t_y;
    c9_I -= c9_d_z;
    c9_i++;
    sf_mex_listen_for_ctrl_c(chartInstance->S);
  }

  CV_EML_FOR(0, 1, 0, 0);
  _SFD_EML_CALL(0U, chartInstance->c9_sfEvent, -38);
  sf_debug_symbol_scope_pop();
  *c9_b_I = c9_I;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 8U, chartInstance->c9_sfEvent);
}
Пример #5
0
static void sf_gateway_c6_CSE1_DP(SFc6_CSE1_DPInstanceStruct *chartInstance)
{
  real_T c6_hoistedGlobal;
  real_T c6_u_BT;
  int32_T c6_i0;
  real_T c6_nu[3];
  uint32_T c6_debug_family_var_map[15];
  real_T c6_u;
  real_T c6_a;
  real_T c6_b;
  real_T c6_c;
  real_T c6_d;
  real_T c6_y0;
  real_T c6_a0;
  real_T c6_a1;
  real_T c6_b1;
  real_T c6_c1;
  real_T c6_nargin = 2.0;
  real_T c6_nargout = 1.0;
  real_T c6_F_y;
  real_T c6_x;
  real_T c6_b_x;
  real_T c6_c_x;
  real_T c6_d_x;
  real_T c6_e_x;
  real_T c6_f_x;
  real_T c6_g_x;
  real_T c6_h_x;
  real_T c6_i_x;
  real_T c6_j_x;
  real_T c6_A;
  real_T c6_k_x;
  real_T c6_l_x;
  real_T c6_m_x;
  int32_T c6_i1;
  real_T *c6_b_u_BT;
  real_T *c6_b_F_y;
  real_T (*c6_b_nu)[3];
  c6_b_nu = (real_T (*)[3])ssGetInputPortSignal(chartInstance->S, 1);
  c6_b_F_y = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c6_b_u_BT = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  _SFD_SYMBOL_SCOPE_PUSH(0U, 0U);
  _sfTime_ = sf_get_time(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 5U, chartInstance->c6_sfEvent);
  _SFD_DATA_RANGE_CHECK(*c6_b_u_BT, 0U);
  chartInstance->c6_sfEvent = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 5U, chartInstance->c6_sfEvent);
  c6_hoistedGlobal = *c6_b_u_BT;
  c6_u_BT = c6_hoistedGlobal;
  for (c6_i0 = 0; c6_i0 < 3; c6_i0++) {
    c6_nu[c6_i0] = (*c6_b_nu)[c6_i0];
  }

  _SFD_SYMBOL_SCOPE_PUSH_EML(0U, 15U, 15U, c6_debug_family_names,
    c6_debug_family_var_map);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c6_u, 0U, c6_sf_marshallOut,
    c6_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c6_a, 1U, c6_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c6_b, 2U, c6_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c6_c, 3U, c6_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c6_d, 4U, c6_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c6_y0, 5U, c6_sf_marshallOut,
    c6_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c6_a0, 6U, c6_sf_marshallOut,
    c6_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c6_a1, 7U, c6_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c6_b1, 8U, c6_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c6_c1, 9U, c6_sf_marshallOut,
    c6_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c6_nargin, 10U, c6_sf_marshallOut,
    c6_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c6_nargout, 11U, c6_sf_marshallOut,
    c6_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c6_u_BT, 12U, c6_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(c6_nu, 13U, c6_b_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c6_F_y, 14U, c6_sf_marshallOut,
    c6_sf_marshallIn);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 3);
  c6_u = c6_nu[0];
  _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 5);
  if (CV_EML_IF(0, 1, 0, c6_u_BT > 0.0879)) {
    _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 6);
    c6_a = 2.515;
    _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 7);
    c6_b = 0.1174;
    _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 8);
    c6_c = -2.807;
    _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 9);
    c6_d = -1.131;
    _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 10);
    c6_x = 0.1174 * c6_u_BT;
    c6_b_x = c6_x;
    c6_b_x = muDoubleScalarExp(c6_b_x);
    c6_c_x = -1.131 * c6_u_BT;
    c6_d_x = c6_c_x;
    c6_d_x = muDoubleScalarExp(c6_d_x);
    c6_y0 = 2.515 * c6_b_x + -2.807 * c6_d_x;
  } else {
    _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 11);
    if (CV_EML_IF(0, 1, 1, c6_u_BT < -0.059)) {
      _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 12);
      c6_a = -548.0;
      _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 13);
      c6_b = 0.193;
      _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 14);
      c6_c = 548.2;
      _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 15);
      c6_d = 0.1992;
      _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 16);
      c6_e_x = 0.193 * c6_u_BT;
      c6_f_x = c6_e_x;
      c6_f_x = muDoubleScalarExp(c6_f_x);
      c6_g_x = 0.1992 * c6_u_BT;
      c6_h_x = c6_g_x;
      c6_h_x = muDoubleScalarExp(c6_h_x);
      c6_y0 = -548.0 * c6_f_x + 548.2 * c6_h_x;
    } else {
      _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 18);
      c6_y0 = 0.0;
    }
  }

  _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 21);
  c6_a0 = 0.7561;
  _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 22);
  c6_a1 = 0.3075;
  _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 23);
  c6_b1 = -10.22;
  _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 24);
  c6_c1 = 2.947;
  _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, 25);
  c6_i_x = -10.22 * c6_u + c6_c1;
  c6_j_x = c6_i_x;
  c6_j_x = muDoubleScalarAtan(c6_j_x);
  c6_A = c6_y0 * (c6_a0 + 0.3075 * c6_j_x);
  c6_k_x = c6_A;
  c6_l_x = c6_k_x;
  c6_m_x = c6_l_x;
  c6_F_y = c6_m_x / 1.1385;
  _SFD_EML_CALL(0U, chartInstance->c6_sfEvent, -25);
  _SFD_SYMBOL_SCOPE_POP();
  *c6_b_F_y = c6_F_y;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 5U, chartInstance->c6_sfEvent);
  _SFD_SYMBOL_SCOPE_POP();
  _SFD_CHECK_FOR_STATE_INCONSISTENCY(_CSE1_DPMachineNumber_,
    chartInstance->chartNumber, chartInstance->instanceNumber);
  _SFD_DATA_RANGE_CHECK(*c6_b_F_y, 1U);
  for (c6_i1 = 0; c6_i1 < 3; c6_i1++) {
    _SFD_DATA_RANGE_CHECK((*c6_b_nu)[c6_i1], 2U);
  }
}
Пример #6
0
/*
 * function [frq,mr] = mel2frq(mel)
 */
void mel2frq(a_melcepstStackData *SD, const real_T mel[4], real_T frq[4])
{
    int32_T k;
    real_T x;
    /* MEL2FRQ  Convert Mel frequency scale to Hertz FRQ=(MEL) */
    /* 	frq = mel2frq(mel) converts a vector of Mel frequencies */
    /* 	to the corresponding real frequencies. */
    /*    mr gives the corresponding gradients in Hz/mel. */
    /* 	The Mel scale corresponds to the perceived pitch of a tone */
    /* 	The relationship between mel and frq is given by: */
    /*  */
    /* 	m = ln(1 + f/700) * 1000 / ln(1+1000/700) */
    /*  */
    /*   	This means that m(1000) = 1000 */
    /*  */
    /* 	References: */
    /*  */
    /* 	  [1] S. S. Stevens & J. Volkman "The relation of pitch to */
    /* 		frequency", American J of Psychology, V 53, p329 1940 */
    /* 	  [2] C. G. M. Fant, "Acoustic description & classification */
    /* 		of phonetic units", Ericsson Tchnics, No 1 1959 */
    /* 		(reprinted in "Speech Sounds & Features", MIT Press 1973) */
    /* 	  [3] S. B. Davis & P. Mermelstein, "Comparison of parametric */
    /* 		representations for monosyllabic word recognition in */
    /* 		continuously spoken sentences", IEEE ASSP, V 28, */
    /* 		pp 357-366 Aug 1980 */
    /* 	  [4] J. R. Deller Jr, J. G. Proakis, J. H. L. Hansen, */
    /* 		"Discrete-Time Processing of Speech Signals", p380, */
    /* 		Macmillan 1993 */
    /* 	  [5] HTK Reference Manual p73 */
    /* 	 */
    /*       Copyright (C) Mike Brookes 1998 */
    /*       Version: $Id: mel2frq.m,v 1.7 2010/08/01 08:41:57 dmb Exp $ */
    /*  */
    /*    VOICEBOX is a MATLAB toolbox for speech processing. */
    /*    Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html */
    /*  */
    /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    /*    This program is free software; you can redistribute it and/or modify */
    /*    it under the terms of the GNU General Public License as published by */
    /*    the Free Software Foundation; either version 2 of the License, or */
    /*    (at your option) any later version. */
    /*  */
    /*    This program is distributed in the hope that it will be useful, */
    /*    but WITHOUT ANY WARRANTY; without even the implied warranty of */
    /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
    /*    GNU General Public License for more details. */
    /*  */
    /*    You can obtain a copy of the GNU General Public License from */
    /*    http://www.gnu.org/copyleft/gpl.html or by writing to */
    /*    Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. */
    /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    /* 'mel2frq:55' if isempty(k) */
    /* 'mel2frq:58' frq=700*sign(mel).*(exp(abs(mel)/k)-1); */
    EMLRTPUSHRTSTACK(&ab_emlrtRSI);
    for (k = 0; k < 4; k++) {
        frq[k] = mel[k];
    }
    for (k = 0; k < 4; k++) {
        x = frq[k];
        if (frq[k] > 0.0) {
            x = 1.0;
        } else if (frq[k] < 0.0) {
            x = -1.0;
        } else {
            if (frq[k] == 0.0) {
                x = 0.0;
            }
        }
        frq[k] = x;
    }
    for (k = 0; k < 4; k++) {
        frq[k] = 700.0 * frq[k] * (muDoubleScalarExp(muDoubleScalarAbs(mel[k]) / SD->pd->b_k) - 1.0);
    }
    EMLRTPOPRTSTACK(&ab_emlrtRSI);
    /* 'mel2frq:59' mr=(700+abs(frq))/k; */
    EMLRTPUSHRTSTACK(&bb_emlrtRSI);
    EMLRTPOPRTSTACK(&bb_emlrtRSI);
    /* 'mel2frq:60' if ~nargout */
}
Пример #7
0
real_T b_scalar_erf(real_T x)
{
  real_T y;
  real_T absx;
  real_T s;
  real_T S;
  real_T R;
  int32_T eint;

  /* ========================== COPYRIGHT NOTICE ============================ */
  /*  The algorithms for calculating ERF(X) and ERFC(X) are derived           */
  /*  from FDLIBM, which has the following notice:                            */
  /*                                                                          */
  /*  Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.       */
  /*                                                                          */
  /*  Developed at SunSoft, a Sun Microsystems, Inc. business.                */
  /*  Permission to use, copy, modify, and distribute this                    */
  /*  software is freely granted, provided that this notice                   */
  /*  is preserved.                                                           */
  /* =============================    END    ================================ */
  absx = muDoubleScalarAbs(x);
  if (muDoubleScalarIsNaN(x)) {
    y = x;
  } else if (muDoubleScalarIsInf(x)) {
    if (x < 0.0) {
      y = -1.0;
    } else {
      y = 1.0;
    }
  } else if (absx < 0.84375) {
    if (absx < 3.7252902984619141E-9) {
      if (absx < 2.8480945388892178E-306) {
        y = 0.125 * (8.0 * x + 1.0270333367641007 * x);
      } else {
        y = x + 0.12837916709551259 * x;
      }
    } else {
      s = x * x;
      y = x + x * ((0.12837916709551256 + s * (-0.3250421072470015 + s *
        (-0.02848174957559851 + s * (-0.0057702702964894416 + s *
        -2.3763016656650163E-5)))) / (1.0 + s * (0.39791722395915535 + s *
        (0.0650222499887673 + s * (0.0050813062818757656 + s *
        (0.00013249473800432164 + s * -3.9602282787753681E-6))))));
    }
  } else if (absx < 1.25) {
    S = -0.0023621185607526594 + (absx - 1.0) * (0.41485611868374833 + (absx -
      1.0) * (-0.37220787603570132 + (absx - 1.0) * (0.31834661990116175 + (absx
      - 1.0) * (-0.11089469428239668 + (absx - 1.0) * (0.035478304325618236 +
      (absx - 1.0) * -0.0021663755948687908)))));
    s = 1.0 + (absx - 1.0) * (0.10642088040084423 + (absx - 1.0) *
      (0.540397917702171 + (absx - 1.0) * (0.071828654414196266 + (absx - 1.0) *
                                (0.12617121980876164 + (absx - 1.0) *
      (0.013637083912029051 + (absx - 1.0) * 0.011984499846799107)))));
    if (x >= 0.0) {
      y = 0.84506291151046753 + S / s;
    } else {
      y = -0.84506291151046753 - S / s;
    }
  } else if (absx > 6.0) {
    if (x < 0.0) {
      y = -1.0;
    } else {
      y = 1.0;
    }
  } else {
    s = 1.0 / (absx * absx);
    if (absx < 2.8571434020996094) {
      R = -0.0098649440348471482 + s * (-0.69385857270718176 + s *
        (-10.558626225323291 + s * (-62.375332450326006 + s *
        (-162.39666946257347 + s * (-184.60509290671104 + s * (-81.2874355063066
        + s * -9.8143293441691455))))));
      S = 1.0 + s * (19.651271667439257 + s * (137.65775414351904 + s *
        (434.56587747522923 + s * (645.38727173326788 + s * (429.00814002756783
        + s * (108.63500554177944 + s * (6.5702497703192817 + s *
        -0.0604244152148581)))))));
    } else {
      R = -0.0098649429247001 + s * (-0.799283237680523 + s *
        (-17.757954917754752 + s * (-160.63638485582192 + s *
        (-637.56644336838963 + s * (-1025.0951316110772 + s * -483.5191916086514)))));
      S = 1.0 + s * (30.338060743482458 + s * (325.79251299657392 + s *
        (1536.729586084437 + s * (3199.8582195085955 + s * (2553.0504064331644 +
        s * (474.52854120695537 + s * -22.440952446585818))))));
    }

    if ((!muDoubleScalarIsInf(absx)) && (!muDoubleScalarIsNaN(absx))) {
      s = frexp(absx, &eint);
    } else {
      s = absx;
      eint = 0;
    }

    s = muDoubleScalarFloor(s * 2.097152E+6) / 2.097152E+6 * muDoubleScalarPower
      (2.0, eint);
    y = muDoubleScalarExp(-s * s - 0.5625) * muDoubleScalarExp((s - absx) * (s +
      absx) + R / S) / absx;
    if (x < 0.0) {
      y--;
    } else {
      y = 1.0 - y;
    }
  }

  return y;
}
Пример #8
0
void b_Acoeff(const emlrtStack *sp, real_T ksi, real_T j, const emxArray_real_T *
              x, real_T t, const emxArray_real_T *gridT, emxArray_real_T *vals)
{
  emxArray_real_T *b;
  emxArray_real_T *r8;
  int32_T b_x;
  int32_T i;
  emxArray_boolean_T *b_t;
  real_T c_x;
  emxArray_boolean_T *c_t;
  emxArray_real_T *z0;
  emxArray_real_T *d_x;
  emxArray_real_T *e_x;
  emxArray_real_T *r9;
  int32_T b_b[2];
  int32_T f_x[2];
  emxArray_real_T *g_x;
  emxArray_real_T *r10;
  const mxArray *y;
  static const int32_T iv16[2] = { 1, 45 };

  const mxArray *m6;
  char_T cv18[45];
  static const char_T cv19[45] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 'm', 't', 'i', 'm', 'e', 's', '_', 'n', 'o', 'D',
    'y', 'n', 'a', 'm', 'i', 'c', 'S', 'c', 'a', 'l', 'a', 'r', 'E', 'x', 'p',
    'a', 'n', 's', 'i', 'o', 'n' };

  const mxArray *b_y;
  static const int32_T iv17[2] = { 1, 21 };

  char_T cv20[21];
  static const char_T cv21[21] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'i', 'n', 'n', 'e', 'r', 'd', 'i', 'm' };

  emxArray_boolean_T *d_t;
  real_T h_x;
  emxArray_boolean_T *e_t;
  emxArray_real_T *i_x;
  emxArray_real_T *r11;
  emxArray_real_T *j_x;
  emxArray_real_T *r12;
  emxArray_real_T *z1;
  int32_T b_z0[2];
  emxArray_real_T *c_z0;
  emxArray_real_T *k_x;
  const mxArray *c_y;
  static const int32_T iv18[2] = { 1, 45 };

  const mxArray *d_y;
  static const int32_T iv19[2] = { 1, 21 };

  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &b_st;
  d_st.tls = b_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T(sp, &b, 2, &bb_emlrtRTEI, true);
  emxInit_real_T(sp, &r8, 2, &bb_emlrtRTEI, true);

  /*  evaluate the coefficient A at the  boundary ksi=0 or ksi=1; */
  /*  for the index j which describes the time steps timePoints_j, at time t and space */
  /*  point x */
  /*  timePoints is a vector describing the time descritized domain */
  b_x = gridT->size[1];
  i = (int32_T)emlrtIntegerCheckFastR2012b(j, &emlrtDCI, sp);
  if (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &d_emlrtBCI,
       sp) - 1]) {
    b_x = vals->size[0] * vals->size[1];
    vals->size[0] = 1;
    vals->size[1] = 1;
    emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof(real_T),
                      &bb_emlrtRTEI);
    vals->data[0] = 0.0;
  } else {
    emxInit_boolean_T(sp, &b_t, 2, &bb_emlrtRTEI, true);
    b_x = b_t->size[0] * b_t->size[1];
    b_t->size[0] = 1;
    b_t->size[1] = 2 + x->size[1];
    emxEnsureCapacity(sp, (emxArray__common *)b_t, b_x, (int32_T)sizeof
                      (boolean_T), &bb_emlrtRTEI);
    b_x = gridT->size[1];
    i = (int32_T)j;
    b_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
      &e_emlrtBCI, sp) - 1]);
    b_x = gridT->size[1];
    i = (int32_T)((uint32_T)j + 1U);
    b_t->data[b_t->size[0]] = (t <= gridT->
      data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &f_emlrtBCI, sp) - 1]);
    i = x->size[1];
    for (b_x = 0; b_x < i; b_x++) {
      b_t->data[b_t->size[0] * (b_x + 2)] = (x->data[x->size[0] * b_x] == ksi);
    }

    st.site = &pe_emlrtRSI;
    if (all(&st, b_t)) {
      b_x = gridT->size[1];
      i = (int32_T)j;
      emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &c_emlrtBCI, sp);
      c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
      st.site = &emlrtRSI;
      if (c_x < 0.0) {
        b_st.site = &f_emlrtRSI;
        eml_error(&b_st);
      }

      b_x = vals->size[0] * vals->size[1];
      vals->size[0] = 1;
      vals->size[1] = 1;
      emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                        (real_T), &bb_emlrtRTEI);
      vals->data[0] = muDoubleScalarSqrt(c_x);
    } else {
      emxInit_boolean_T(sp, &c_t, 2, &bb_emlrtRTEI, true);
      b_x = c_t->size[0] * c_t->size[1];
      c_t->size[0] = 1;
      c_t->size[1] = 2 + x->size[1];
      emxEnsureCapacity(sp, (emxArray__common *)c_t, b_x, (int32_T)sizeof
                        (boolean_T), &bb_emlrtRTEI);
      b_x = gridT->size[1];
      i = (int32_T)j;
      c_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
        b_x, &g_emlrtBCI, sp) - 1]);
      b_x = gridT->size[1];
      i = (int32_T)((uint32_T)j + 1U);
      c_t->data[c_t->size[0]] = (t <= gridT->
        data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &h_emlrtBCI, sp) - 1]);
      i = x->size[1];
      for (b_x = 0; b_x < i; b_x++) {
        c_t->data[c_t->size[0] * (b_x + 2)] = (x->data[x->size[0] * b_x] != ksi);
      }

      emxInit_real_T(sp, &z0, 2, &cb_emlrtRTEI, true);
      emxInit_real_T(sp, &d_x, 2, &bb_emlrtRTEI, true);
      st.site = &qe_emlrtRSI;
      if (all(&st, c_t)) {
        st.site = &b_emlrtRSI;
        b_x = gridT->size[1];
        i = (int32_T)j;
        c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
          &m_emlrtBCI, &st) - 1];
        if (c_x < 0.0) {
          b_st.site = &f_emlrtRSI;
          eml_error(&b_st);
        }

        emxInit_real_T(&st, &e_x, 2, &bb_emlrtRTEI, true);
        b_x = e_x->size[0] * e_x->size[1];
        e_x->size[0] = 1;
        e_x->size[1] = x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)e_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = x->size[0] * x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          e_x->data[b_x] = x->data[b_x] - ksi;
        }

        emxInit_real_T(sp, &r9, 2, &bb_emlrtRTEI, true);
        b_abs(sp, e_x, r9);
        b_x = r8->size[0] * r8->size[1];
        r8->size[0] = 1;
        r8->size[1] = r9->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = r9->size[0] * r9->size[1];
        emxFree_real_T(&e_x);
        for (b_x = 0; b_x < i; b_x++) {
          r8->data[b_x] = r9->data[b_x];
        }

        emxFree_real_T(&r9);
        rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z0);
        st.site = &re_emlrtRSI;
        mpower(&st, z0, d_x);
        b_x = d_x->size[0] * d_x->size[1];
        d_x->size[0] = 1;
        emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = d_x->size[0];
        b_x = d_x->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          d_x->data[b_x] = -d_x->data[b_x];
        }

        b_x = b->size[0] * b->size[1];
        b->size[0] = 1;
        b->size[1] = d_x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)b, b_x, (int32_T)sizeof(real_T),
                          &bb_emlrtRTEI);
        i = d_x->size[0] * d_x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          b->data[b_x] = d_x->data[b_x];
        }

        for (i = 0; i < d_x->size[1]; i++) {
          b->data[i] = muDoubleScalarExp(b->data[i]);
        }

        st.site = &re_emlrtRSI;
        b_mrdivide(&st, b, z0);
        for (b_x = 0; b_x < 2; b_x++) {
          i = d_x->size[0] * d_x->size[1];
          d_x->size[b_x] = z0->size[b_x];
          emxEnsureCapacity(sp, (emxArray__common *)d_x, i, (int32_T)sizeof
                            (real_T), &ab_emlrtRTEI);
        }

        for (i = 0; i < z0->size[1]; i++) {
          d_x->data[i] = scalar_erf(z0->data[i]);
        }

        b_x = d_x->size[0] * d_x->size[1];
        d_x->size[0] = 1;
        emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = d_x->size[0];
        b_x = d_x->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          d_x->data[b_x] *= 1.7724538509055159;
        }

        for (b_x = 0; b_x < 2; b_x++) {
          b_b[b_x] = b->size[b_x];
        }

        for (b_x = 0; b_x < 2; b_x++) {
          f_x[b_x] = d_x->size[b_x];
        }

        emxInit_real_T(sp, &g_x, 2, &bb_emlrtRTEI, true);
        emlrtSizeEqCheck2DFastR2012b(b_b, f_x, &o_emlrtECI, sp);
        b_x = g_x->size[0] * g_x->size[1];
        g_x->size[0] = 1;
        g_x->size[1] = x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)g_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = x->size[0] * x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          g_x->data[b_x] = x->data[b_x] - ksi;
        }

        emxInit_real_T(sp, &r10, 2, &bb_emlrtRTEI, true);
        b_abs(sp, g_x, r10);
        b_x = r8->size[0] * r8->size[1];
        r8->size[0] = 1;
        r8->size[1] = r10->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = r10->size[0] * r10->size[1];
        emxFree_real_T(&g_x);
        for (b_x = 0; b_x < i; b_x++) {
          r8->data[b_x] = r10->data[b_x];
        }

        emxFree_real_T(&r10);
        rdivide(sp, r8, 3.5449077018110318, vals);
        st.site = &re_emlrtRSI;
        b_x = b->size[0] * b->size[1];
        b->size[0] = 1;
        emxEnsureCapacity(&st, (emxArray__common *)b, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = b->size[0];
        b_x = b->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          b->data[b_x] -= d_x->data[b_x];
        }

        b_st.site = &he_emlrtRSI;
        if (!(vals->size[1] == 1)) {
          if ((vals->size[1] == 1) || (b->size[1] == 1)) {
            y = NULL;
            m6 = emlrtCreateCharArray(2, iv16);
            for (i = 0; i < 45; i++) {
              cv18[i] = cv19[i];
            }

            emlrtInitCharArrayR2013a(&b_st, 45, m6, cv18);
            emlrtAssign(&y, m6);
            c_st.site = &fh_emlrtRSI;
            d_st.site = &vg_emlrtRSI;
            b_error(&c_st, message(&d_st, y, &j_emlrtMCI), &k_emlrtMCI);
          } else {
            b_y = NULL;
            m6 = emlrtCreateCharArray(2, iv17);
            for (i = 0; i < 21; i++) {
              cv20[i] = cv21[i];
            }

            emlrtInitCharArrayR2013a(&b_st, 21, m6, cv20);
            emlrtAssign(&b_y, m6);
            c_st.site = &gh_emlrtRSI;
            d_st.site = &wg_emlrtRSI;
            b_error(&c_st, message(&d_st, b_y, &l_emlrtMCI), &m_emlrtMCI);
          }
        }

        c_x = vals->data[0];
        b_x = vals->size[0] * vals->size[1];
        vals->size[0] = 1;
        vals->size[1] = b->size[1];
        emxEnsureCapacity(&st, (emxArray__common *)vals, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = b->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          vals->data[vals->size[0] * b_x] = c_x * b->data[b->size[0] * b_x];
        }
      } else {
        emxInit_boolean_T(sp, &d_t, 2, &bb_emlrtRTEI, true);
        b_x = d_t->size[0] * d_t->size[1];
        d_t->size[0] = 1;
        d_t->size[1] = 1 + x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)d_t, b_x, (int32_T)sizeof
                          (boolean_T), &bb_emlrtRTEI);
        b_x = gridT->size[1];
        i = (int32_T)((uint32_T)j + 1U);
        d_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
          b_x, &i_emlrtBCI, sp) - 1]);
        i = x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          d_t->data[d_t->size[0] * (b_x + 1)] = (x->data[x->size[0] * b_x] ==
            ksi);
        }

        st.site = &se_emlrtRSI;
        if (all(&st, d_t)) {
          b_x = gridT->size[1];
          i = (int32_T)j;
          emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &b_emlrtBCI, sp);
          c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
          b_x = gridT->size[1];
          i = (int32_T)(j + 1.0);
          emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &emlrtBCI, sp);
          h_x = (t - gridT->data[(int32_T)(j + 1.0) - 1]) / 3.1415926535897931;
          st.site = &c_emlrtRSI;
          if (c_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          st.site = &c_emlrtRSI;
          if (h_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          b_x = vals->size[0] * vals->size[1];
          vals->size[0] = 1;
          vals->size[1] = 1;
          emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                            (real_T), &bb_emlrtRTEI);
          vals->data[0] = muDoubleScalarSqrt(c_x) - muDoubleScalarSqrt(h_x);
        } else {
          emxInit_boolean_T(sp, &e_t, 2, &bb_emlrtRTEI, true);
          b_x = e_t->size[0] * e_t->size[1];
          e_t->size[0] = 1;
          e_t->size[1] = 1 + x->size[1];
          emxEnsureCapacity(sp, (emxArray__common *)e_t, b_x, (int32_T)sizeof
                            (boolean_T), &bb_emlrtRTEI);
          b_x = gridT->size[1];
          i = (int32_T)((uint32_T)j + 1U);
          e_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
            b_x, &j_emlrtBCI, sp) - 1]);
          i = x->size[1];
          for (b_x = 0; b_x < i; b_x++) {
            e_t->data[e_t->size[0] * (b_x + 1)] = (x->data[x->size[0] * b_x] !=
              ksi);
          }

          st.site = &te_emlrtRSI;
          if (all(&st, e_t)) {
            st.site = &d_emlrtRSI;
            b_x = gridT->size[1];
            i = (int32_T)j;
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
              &k_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            emxInit_real_T(&st, &i_x, 2, &bb_emlrtRTEI, true);
            b_x = i_x->size[0] * i_x->size[1];
            i_x->size[0] = 1;
            i_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)i_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              i_x->data[b_x] = x->data[b_x] - ksi;
            }

            emxInit_real_T(sp, &r11, 2, &bb_emlrtRTEI, true);
            b_abs(sp, i_x, r11);
            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = r11->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = r11->size[0] * r11->size[1];
            emxFree_real_T(&i_x);
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = r11->data[b_x];
            }

            emxFree_real_T(&r11);
            rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z0);
            st.site = &e_emlrtRSI;
            b_x = gridT->size[1];
            i = (int32_T)((uint32_T)j + 1U);
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
              &l_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            emxInit_real_T(&st, &j_x, 2, &bb_emlrtRTEI, true);
            b_x = j_x->size[0] * j_x->size[1];
            j_x->size[0] = 1;
            j_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)j_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              j_x->data[b_x] = x->data[b_x] - ksi;
            }

            emxInit_real_T(sp, &r12, 2, &bb_emlrtRTEI, true);
            b_abs(sp, j_x, r12);
            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = r12->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = r12->size[0] * r12->size[1];
            emxFree_real_T(&j_x);
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = r12->data[b_x];
            }

            emxFree_real_T(&r12);
            emxInit_real_T(sp, &z1, 2, &db_emlrtRTEI, true);
            rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z1);
            st.site = &ue_emlrtRSI;
            mpower(&st, z0, d_x);
            b_x = d_x->size[0] * d_x->size[1];
            d_x->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0];
            b_x = d_x->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              d_x->data[b_x] = -d_x->data[b_x];
            }

            b_x = b->size[0] * b->size[1];
            b->size[0] = 1;
            b->size[1] = d_x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)b, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0] * d_x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              b->data[b_x] = d_x->data[b_x];
            }

            for (i = 0; i < d_x->size[1]; i++) {
              b->data[i] = muDoubleScalarExp(b->data[i]);
            }

            st.site = &ue_emlrtRSI;
            b_mrdivide(&st, b, z0);
            st.site = &ue_emlrtRSI;
            mpower(&st, z1, d_x);
            b_x = d_x->size[0] * d_x->size[1];
            d_x->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0];
            b_x = d_x->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              d_x->data[b_x] = -d_x->data[b_x];
            }

            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = d_x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0] * d_x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = d_x->data[b_x];
            }

            for (i = 0; i < d_x->size[1]; i++) {
              r8->data[i] = muDoubleScalarExp(r8->data[i]);
            }

            st.site = &ue_emlrtRSI;
            b_mrdivide(&st, r8, z1);
            for (b_x = 0; b_x < 2; b_x++) {
              b_b[b_x] = b->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = r8->size[b_x];
            }

            emxInit_real_T(sp, &c_z0, 2, &bb_emlrtRTEI, true);
            emlrtSizeEqCheck2DFastR2012b(b_b, b_z0, &m_emlrtECI, sp);
            b_x = c_z0->size[0] * c_z0->size[1];
            c_z0->size[0] = 1;
            c_z0->size[1] = z0->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)c_z0, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = z0->size[0] * z0->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              c_z0->data[b_x] = z0->data[b_x];
            }

            b_erf(sp, c_z0, z0);
            b_erf(sp, z1, d_x);
            emxFree_real_T(&c_z0);
            emxFree_real_T(&z1);
            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = z0->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              f_x[b_x] = d_x->size[b_x];
            }

            emlrtSizeEqCheck2DFastR2012b(b_z0, f_x, &n_emlrtECI, sp);
            b_x = z0->size[0] * z0->size[1];
            z0->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)z0, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = z0->size[0];
            b_x = z0->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              z0->data[b_x] = 1.7724538509055159 * (z0->data[b_x] - d_x->
                data[b_x]);
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_b[b_x] = b->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = z0->size[b_x];
            }

            emxInit_real_T(sp, &k_x, 2, &bb_emlrtRTEI, true);
            emlrtSizeEqCheck2DFastR2012b(b_b, b_z0, &m_emlrtECI, sp);
            b_x = k_x->size[0] * k_x->size[1];
            k_x->size[0] = 1;
            k_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)k_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              k_x->data[b_x] = x->data[b_x] - ksi;
            }

            b_abs(sp, k_x, d_x);
            rdivide(sp, d_x, 3.5449077018110318, vals);
            st.site = &ue_emlrtRSI;
            b_x = b->size[0] * b->size[1];
            b->size[0] = 1;
            emxEnsureCapacity(&st, (emxArray__common *)b, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = b->size[0];
            b_x = b->size[1];
            i *= b_x;
            emxFree_real_T(&k_x);
            for (b_x = 0; b_x < i; b_x++) {
              b->data[b_x] = (b->data[b_x] - r8->data[b_x]) + z0->data[b_x];
            }

            b_st.site = &he_emlrtRSI;
            if (!(vals->size[1] == 1)) {
              if ((vals->size[1] == 1) || (b->size[1] == 1)) {
                c_y = NULL;
                m6 = emlrtCreateCharArray(2, iv18);
                for (i = 0; i < 45; i++) {
                  cv18[i] = cv19[i];
                }

                emlrtInitCharArrayR2013a(&b_st, 45, m6, cv18);
                emlrtAssign(&c_y, m6);
                c_st.site = &fh_emlrtRSI;
                d_st.site = &vg_emlrtRSI;
                b_error(&c_st, message(&d_st, c_y, &j_emlrtMCI), &k_emlrtMCI);
              } else {
                d_y = NULL;
                m6 = emlrtCreateCharArray(2, iv19);
                for (i = 0; i < 21; i++) {
                  cv20[i] = cv21[i];
                }

                emlrtInitCharArrayR2013a(&b_st, 21, m6, cv20);
                emlrtAssign(&d_y, m6);
                c_st.site = &gh_emlrtRSI;
                d_st.site = &wg_emlrtRSI;
                b_error(&c_st, message(&d_st, d_y, &l_emlrtMCI), &m_emlrtMCI);
              }
            }

            c_x = vals->data[0];
            b_x = vals->size[0] * vals->size[1];
            vals->size[0] = 1;
            vals->size[1] = b->size[1];
            emxEnsureCapacity(&st, (emxArray__common *)vals, b_x, (int32_T)
                              sizeof(real_T), &bb_emlrtRTEI);
            i = b->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              vals->data[vals->size[0] * b_x] = c_x * b->data[b->size[0] * b_x];
            }
          } else {
            b_x = vals->size[0] * vals->size[1];
            vals->size[0] = 1;
            vals->size[1] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            vals->data[0] = 0.0;
          }

          emxFree_boolean_T(&e_t);
        }

        emxFree_boolean_T(&d_t);
      }

      emxFree_boolean_T(&c_t);
      emxFree_real_T(&d_x);
      emxFree_real_T(&z0);
    }

    emxFree_boolean_T(&b_t);
  }

  emxFree_real_T(&r8);
  emxFree_real_T(&b);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Пример #9
0
/* Function Definitions */
real_T Acoeff(const emlrtStack *sp, real_T ksi, real_T j, real_T x, real_T t,
              const emxArray_real_T *gridT)
{
  real_T vals;
  int32_T k;
  int32_T i0;
  boolean_T b_x[3];
  boolean_T y;
  boolean_T exitg4;
  real_T c_x;
  boolean_T exitg3;
  real_T z0;
  boolean_T d_x[2];
  boolean_T exitg2;
  real_T z1;
  boolean_T exitg1;
  emlrtStack st;
  emlrtStack b_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;

  /*  evaluate the coefficient A at the  boundary ksi=0 or ksi=1; */
  /*  for the index j which describes the time steps timePoints_j, at time t and space */
  /*  point x */
  /*  timePoints is a vector describing the time descritized domain */
  k = gridT->size[1];
  i0 = (int32_T)emlrtIntegerCheckFastR2012b(j, &emlrtDCI, sp);
  if (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k, &d_emlrtBCI,
       sp) - 1]) {
    vals = 0.0;
  } else {
    k = gridT->size[1];
    i0 = (int32_T)j;
    b_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
               &e_emlrtBCI, sp) - 1]);
    k = gridT->size[1];
    i0 = (int32_T)((uint32_T)j + 1U);
    b_x[1] = (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
               &f_emlrtBCI, sp) - 1]);
    b_x[2] = (x == ksi);
    y = true;
    k = 0;
    exitg4 = false;
    while ((!exitg4) && (k < 3)) {
      if (b_x[k] == 0) {
        y = false;
        exitg4 = true;
      } else {
        k++;
      }
    }

    if (y) {
      k = gridT->size[1];
      i0 = (int32_T)j;
      emlrtDynamicBoundsCheckFastR2012b(i0, 1, k, &c_emlrtBCI, sp);
      c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
      st.site = &emlrtRSI;
      if (c_x < 0.0) {
        b_st.site = &f_emlrtRSI;
        eml_error(&b_st);
      }

      vals = muDoubleScalarSqrt(c_x);
    } else {
      k = gridT->size[1];
      i0 = (int32_T)j;
      b_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
                 &g_emlrtBCI, sp) - 1]);
      k = gridT->size[1];
      i0 = (int32_T)((uint32_T)j + 1U);
      b_x[1] = (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
                 &h_emlrtBCI, sp) - 1]);
      b_x[2] = (x != ksi);
      y = true;
      k = 0;
      exitg3 = false;
      while ((!exitg3) && (k < 3)) {
        if (b_x[k] == 0) {
          y = false;
          exitg3 = true;
        } else {
          k++;
        }
      }

      if (y) {
        st.site = &b_emlrtRSI;
        k = gridT->size[1];
        i0 = (int32_T)j;
        c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
          &m_emlrtBCI, &st) - 1];
        if (c_x < 0.0) {
          b_st.site = &f_emlrtRSI;
          eml_error(&b_st);
        }

        z0 = muDoubleScalarAbs(x - ksi) / (2.0 * muDoubleScalarSqrt(c_x));
        vals = muDoubleScalarAbs(x - ksi) / 3.5449077018110318 *
          (muDoubleScalarExp(-(z0 * z0)) / z0 - 1.7724538509055159 * scalar_erf
           (z0));
      } else {
        k = gridT->size[1];
        i0 = (int32_T)((uint32_T)j + 1U);
        d_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
                   &i_emlrtBCI, sp) - 1]);
        d_x[1] = (x == ksi);
        y = true;
        k = 0;
        exitg2 = false;
        while ((!exitg2) && (k < 2)) {
          if (d_x[k] == 0) {
            y = false;
            exitg2 = true;
          } else {
            k++;
          }
        }

        if (y) {
          k = gridT->size[1];
          i0 = (int32_T)j;
          emlrtDynamicBoundsCheckFastR2012b(i0, 1, k, &b_emlrtBCI, sp);
          c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
          k = gridT->size[1];
          i0 = (int32_T)(j + 1.0);
          emlrtDynamicBoundsCheckFastR2012b(i0, 1, k, &emlrtBCI, sp);
          z1 = (t - gridT->data[(int32_T)(j + 1.0) - 1]) / 3.1415926535897931;
          st.site = &c_emlrtRSI;
          if (c_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          st.site = &c_emlrtRSI;
          if (z1 < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          vals = muDoubleScalarSqrt(c_x) - muDoubleScalarSqrt(z1);
        } else {
          k = gridT->size[1];
          i0 = (int32_T)((uint32_T)j + 1U);
          d_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
                     &j_emlrtBCI, sp) - 1]);
          d_x[1] = (x != ksi);
          y = true;
          k = 0;
          exitg1 = false;
          while ((!exitg1) && (k < 2)) {
            if (d_x[k] == 0) {
              y = false;
              exitg1 = true;
            } else {
              k++;
            }
          }

          if (y) {
            st.site = &d_emlrtRSI;
            k = gridT->size[1];
            i0 = (int32_T)j;
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
              &k_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            z0 = muDoubleScalarAbs(x - ksi) / (2.0 * muDoubleScalarSqrt(c_x));
            st.site = &e_emlrtRSI;
            k = gridT->size[1];
            i0 = (int32_T)((uint32_T)j + 1U);
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
              &l_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            z1 = muDoubleScalarAbs(x - ksi) / (2.0 * muDoubleScalarSqrt(c_x));
            vals = muDoubleScalarAbs(x - ksi) / 3.5449077018110318 *
              ((muDoubleScalarExp(-(z0 * z0)) / z0 - muDoubleScalarExp(-(z1 * z1))
                / z1) + 1.7724538509055159 * (b_scalar_erf(z0) - b_scalar_erf(z1)));
          } else {
            vals = 0.0;
          }
        }
      }
    }
  }

  return vals;
}
Пример #10
0
real_T logpdf(const emxArray_real_T *x, const emxArray_real_T *A, real_T C)
{
  real_T f;
  emxArray_real_T *a;
  int32_T i2;
  int32_T i;
  const mxArray *y;
  static const int32_T iv2[2] = { 1, 45 };

  const mxArray *m0;
  char_T cv1[45];
  static const char_T cv2[45] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 'm', 't', 'i', 'm', 'e', 's', '_', 'n', 'o', 'D',
    'y', 'n', 'a', 'm', 'i', 'c', 'S', 'c', 'a', 'l', 'a', 'r', 'E', 'x', 'p',
    'a', 'n', 's', 'i', 'o', 'n' };

  const mxArray *b_y;
  static const int32_T iv3[2] = { 1, 21 };

  char_T cv3[21];
  static const char_T cv4[21] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'i', 'n', 'n', 'e', 'r', 'd', 'i', 'm' };

  emxArray_real_T *c_y;
  int32_T loop_ub;
  int32_T i3;
  uint32_T unnamed_idx_0;
  real_T alpha1;
  real_T beta1;
  char_T TRANSB;
  char_T TRANSA;
  ptrdiff_t m_t;
  ptrdiff_t n_t;
  ptrdiff_t k_t;
  ptrdiff_t lda_t;
  ptrdiff_t ldb_t;
  ptrdiff_t ldc_t;
  double * alpha1_t;
  double * Aia0_t;
  double * Bib0_t;
  double * beta1_t;
  double * Cic0_t;
  emxArray_real_T *b_x;
  boolean_T overflow;
  boolean_T p;
  int32_T exitg1;
  const mxArray *d_y;
  static const int32_T iv4[2] = { 1, 30 };

  char_T cv5[30];
  static const char_T cv6[30] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 's', 'u', 'm', '_', 's', 'p', 'e', 'c', 'i', 'a',
    'l', 'E', 'm', 'p', 't', 'y' };

  const mxArray *e_y;
  static const int32_T iv5[2] = { 1, 36 };

  char_T cv7[36];
  static const char_T cv8[36] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 'a', 'u', 't', 'o', 'D', 'i', 'm', 'I', 'n', 'c',
    'o', 'm', 'p', 'a', 't', 'i', 'b', 'i', 'l', 'i', 't', 'y' };

  emxArray_real_T *b_a;
  const mxArray *f_y;
  static const int32_T iv6[2] = { 1, 45 };

  const mxArray *g_y;
  static const int32_T iv7[2] = { 1, 21 };

  emlrtHeapReferenceStackEnterFcnR2012b(emlrtRootTLSGlobal);
  emxInit_real_T(&a, 2, &e_emlrtRTEI, TRUE);
  emlrtPushRtStackR2012b(&h_emlrtRSI, emlrtRootTLSGlobal);
  i2 = a->size[0] * a->size[1];
  a->size[0] = A->size[0];
  a->size[1] = A->size[1];
  emxEnsureCapacity((emxArray__common *)a, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = A->size[0] * A->size[1];
  for (i2 = 0; i2 < i; i2++) {
    a->data[i2] = -A->data[i2];
  }

  emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
  if (!(a->size[1] == x->size[0])) {
    if (((a->size[0] == 1) && (a->size[1] == 1)) || (x->size[0] == 1)) {
      emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
      y = NULL;
      m0 = mxCreateCharArray(2, iv2);
      for (i = 0; i < 45; i++) {
        cv1[i] = cv2[i];
      }

      emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 45, m0, cv1);
      emlrtAssign(&y, m0);
      error(message(y, &b_emlrtMCI), &c_emlrtMCI);
      emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    } else {
      emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
      b_y = NULL;
      m0 = mxCreateCharArray(2, iv3);
      for (i = 0; i < 21; i++) {
        cv3[i] = cv4[i];
      }

      emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 21, m0, cv3);
      emlrtAssign(&b_y, m0);
      error(message(b_y, &d_emlrtMCI), &e_emlrtMCI);
      emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    }
  }

  emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
  b_emxInit_real_T(&c_y, 1, &e_emlrtRTEI, TRUE);
  if ((a->size[1] == 1) || (x->size[0] == 1)) {
    i2 = c_y->size[0];
    c_y->size[0] = a->size[0];
    emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T),
                      &e_emlrtRTEI);
    i = a->size[0];
    for (i2 = 0; i2 < i; i2++) {
      c_y->data[i2] = 0.0;
      loop_ub = a->size[1];
      for (i3 = 0; i3 < loop_ub; i3++) {
        c_y->data[i2] += a->data[i2 + a->size[0] * i3] * x->data[i3];
      }
    }
  } else {
    unnamed_idx_0 = (uint32_T)a->size[0];
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    i2 = c_y->size[0];
    c_y->size[0] = (int32_T)unnamed_idx_0;
    emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T),
                      &e_emlrtRTEI);
    i = (int32_T)unnamed_idx_0;
    for (i2 = 0; i2 < i; i2++) {
      c_y->data[i2] = 0.0;
    }

    if ((a->size[0] < 1) || (a->size[1] < 1)) {
    } else {
      emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
      alpha1 = 1.0;
      beta1 = 0.0;
      TRANSB = 'N';
      TRANSA = 'N';
      emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      m_t = (ptrdiff_t)(a->size[0]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      n_t = (ptrdiff_t)(1);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      k_t = (ptrdiff_t)(a->size[1]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      lda_t = (ptrdiff_t)(a->size[0]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&y_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      ldb_t = (ptrdiff_t)(a->size[1]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&y_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&ab_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      ldc_t = (ptrdiff_t)(a->size[0]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&ab_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&bb_emlrtRSI, emlrtRootTLSGlobal);
      alpha1_t = (double *)(&alpha1);
      emlrtPopRtStackR2012b(&bb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&cb_emlrtRSI, emlrtRootTLSGlobal);
      Aia0_t = (double *)(&a->data[0]);
      emlrtPopRtStackR2012b(&cb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal);
      Bib0_t = (double *)(&x->data[0]);
      emlrtPopRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal);
      beta1_t = (double *)(&beta1);
      emlrtPopRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal);
      Cic0_t = (double *)(&c_y->data[0]);
      emlrtPopRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal);
      dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
            &ldb_t, beta1_t, Cic0_t, &ldc_t);
      emlrtPopRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    }

    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
  }

  emxFree_real_T(&a);
  b_emxInit_real_T(&b_x, 1, &e_emlrtRTEI, TRUE);
  i2 = b_x->size[0];
  b_x->size[0] = c_y->size[0];
  emxEnsureCapacity((emxArray__common *)b_x, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = c_y->size[0];
  for (i2 = 0; i2 < i; i2++) {
    b_x->data[i2] = c_y->data[i2];
  }

  for (i = 0; i < c_y->size[0]; i++) {
    b_x->data[i] = muDoubleScalarExp(b_x->data[i]);
  }

  i2 = b_x->size[0];
  emxEnsureCapacity((emxArray__common *)b_x, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = b_x->size[0];
  for (i2 = 0; i2 < i; i2++) {
    b_x->data[i2]++;
  }

  i2 = c_y->size[0];
  c_y->size[0] = b_x->size[0];
  emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = b_x->size[0];
  for (i2 = 0; i2 < i; i2++) {
    c_y->data[i2] = b_x->data[i2];
  }

  for (i = 0; i < b_x->size[0]; i++) {
    if (b_x->data[i] < 0.0) {
      emlrtPushRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal);
      eml_error();
      emlrtPopRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal);
    }
  }

  for (i = 0; i < b_x->size[0]; i++) {
    c_y->data[i] = muDoubleScalarLog(c_y->data[i]);
  }

  emxFree_real_T(&b_x);
  overflow = FALSE;
  p = FALSE;
  i = 0;
  do {
    exitg1 = 0;
    if (i < 2) {
      if (i + 1 <= 1) {
        i2 = c_y->size[0];
      } else {
        i2 = 1;
      }

      if (i2 != 0) {
        exitg1 = 1;
      } else {
        i++;
      }
    } else {
      p = TRUE;
      exitg1 = 1;
    }
  } while (exitg1 == 0);

  if (!p) {
  } else {
    overflow = TRUE;
  }

  if (!overflow) {
  } else {
    emlrtPushRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal);
    d_y = NULL;
    m0 = mxCreateCharArray(2, iv4);
    for (i = 0; i < 30; i++) {
      cv5[i] = cv6[i];
    }

    emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 30, m0, cv5);
    emlrtAssign(&d_y, m0);
    error(message(d_y, &h_emlrtMCI), &i_emlrtMCI);
    emlrtPopRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal);
  }

  if ((c_y->size[0] == 1) || (c_y->size[0] != 1)) {
    overflow = TRUE;
  } else {
    overflow = FALSE;
  }

  if (overflow) {
  } else {
    emlrtPushRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal);
    e_y = NULL;
    m0 = mxCreateCharArray(2, iv5);
    for (i = 0; i < 36; i++) {
      cv7[i] = cv8[i];
    }

    emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 36, m0, cv7);
    emlrtAssign(&e_y, m0);
    error(message(e_y, &j_emlrtMCI), &k_emlrtMCI);
    emlrtPopRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal);
  }

  if (c_y->size[0] == 0) {
    alpha1 = 0.0;
  } else {
    alpha1 = c_y->data[0];
    emlrtPushRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal);
    if (2 > c_y->size[0]) {
      overflow = FALSE;
    } else {
      overflow = (c_y->size[0] > 2147483646);
    }

    if (overflow) {
      emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
      check_forloop_overflow_error();
      emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    }

    emlrtPopRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal);
    for (i = 2; i <= c_y->size[0]; i++) {
      alpha1 += c_y->data[i - 1];
    }
  }

  emxFree_real_T(&c_y);
  emxInit_real_T(&b_a, 2, &e_emlrtRTEI, TRUE);
  i2 = b_a->size[0] * b_a->size[1];
  b_a->size[0] = 1;
  emxEnsureCapacity((emxArray__common *)b_a, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = x->size[0];
  i2 = b_a->size[0] * b_a->size[1];
  b_a->size[1] = i;
  emxEnsureCapacity((emxArray__common *)b_a, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = x->size[0];
  for (i2 = 0; i2 < i; i2++) {
    b_a->data[i2] = x->data[i2];
  }

  emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
  if (!(b_a->size[1] == x->size[0])) {
    if ((b_a->size[1] == 1) || (x->size[0] == 1)) {
      emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
      f_y = NULL;
      m0 = mxCreateCharArray(2, iv6);
      for (i = 0; i < 45; i++) {
        cv1[i] = cv2[i];
      }

      emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 45, m0, cv1);
      emlrtAssign(&f_y, m0);
      error(message(f_y, &b_emlrtMCI), &c_emlrtMCI);
      emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    } else {
      emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
      g_y = NULL;
      m0 = mxCreateCharArray(2, iv7);
      for (i = 0; i < 21; i++) {
        cv3[i] = cv4[i];
      }

      emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 21, m0, cv3);
      emlrtAssign(&g_y, m0);
      error(message(g_y, &d_emlrtMCI), &e_emlrtMCI);
      emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    }
  }

  emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
  if ((b_a->size[1] == 1) || (x->size[0] == 1)) {
    beta1 = 0.0;
    for (i2 = 0; i2 < b_a->size[1]; i2++) {
      beta1 += b_a->data[b_a->size[0] * i2] * x->data[i2];
    }
  } else {
    emlrtPushRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal);
    if (b_a->size[1] < 1) {
      beta1 = 0.0;
    } else {
      emlrtPushRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&sb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      n_t = (ptrdiff_t)(b_a->size[1]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&sb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&tb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      m_t = (ptrdiff_t)(1);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&tb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&ub_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      k_t = (ptrdiff_t)(1);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&ub_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&vb_emlrtRSI, emlrtRootTLSGlobal);
      alpha1_t = (double *)(&b_a->data[0]);
      emlrtPopRtStackR2012b(&vb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&wb_emlrtRSI, emlrtRootTLSGlobal);
      Aia0_t = (double *)(&x->data[0]);
      emlrtPopRtStackR2012b(&wb_emlrtRSI, emlrtRootTLSGlobal);
      beta1 = ddot(&n_t, alpha1_t, &m_t, Aia0_t, &k_t);
      emlrtPopRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal);
    }

    emlrtPopRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal);
  }

  emxFree_real_T(&b_a);
  f = -C * alpha1 - 0.5 * beta1;
  emlrtPopRtStackR2012b(&h_emlrtRSI, emlrtRootTLSGlobal);
  emlrtHeapReferenceStackLeaveFcnR2012b(emlrtRootTLSGlobal);
  return f;
}