real_T bisection2(real_T a, real_T b, real_T tol) { real_T p; const mxArray *y; static const int32_T iv0[2] = { 1, 16 }; const mxArray *m0; static const char_T cv0[16] = { 'W', 'r', 'o', 'n', 'g', ' ', 'c', 'h', 'o', 'i', 'c', 'e', ' ', 'b', 'r', 'o' }; real_T err; /* provide the equation you want to solve with R.H.S = 0 form. */ /* Write the L.H.S by using inline function */ /* Give initial guesses. */ /* Solves it by method of bisection. */ /* A very simple code and very handy! */ if ((muDoubleScalarPower(a - 1.5, 3.0) + 10.0) * (muDoubleScalarPower(b - 1.5, 3.0) + 10.0) > 0.0) { EMLRTPUSHRTSTACK(&emlrtRSI); EMLRTPUSHRTSTACK(&b_emlrtRSI); y = NULL; m0 = mxCreateCharArray(2, iv0); emlrtInitCharArray(16, m0, cv0); emlrtAssign(&y, m0); error(y, &emlrtMCI); EMLRTPOPRTSTACK(&b_emlrtRSI); EMLRTPOPRTSTACK(&emlrtRSI); } else { p = (a + b) / 2.0; err = muDoubleScalarAbs(b - a); while (err >= tol) { if ((muDoubleScalarPower(a - 1.5, 3.0) + 10.0) * (muDoubleScalarPower(p - 1.5, 3.0) + 10.0) < 0.0) { b = p; } else { a = p; } p = (a + b) / 2.0; err = muDoubleScalarAbs(b - a); emlrtBreakCheck(); } } return p; }
real_T sum(const emxArray_real_T *x) { real_T y; boolean_T p; boolean_T b_p; int32_T k; int32_T exitg1; int32_T vlen; const mxArray *b_y; static const int32_T iv19[2] = { 1, 30 }; const mxArray *m4; static const char_T cv9[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 *c_y; static const int32_T iv20[2] = { 1, 36 }; static const char_T cv10[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' }; EMLRTPUSHRTSTACK(&pc_emlrtRSI); EMLRTPUSHRTSTACK(&sc_emlrtRSI); p = FALSE; EMLRTPUSHRTSTACK(&tc_emlrtRSI); EMLRTPUSHRTSTACK(&uc_emlrtRSI); b_p = FALSE; k = 0; do { exitg1 = 0U; if (k < 2) { vlen = x->size[k]; if (vlen != 0) { exitg1 = 1U; } else { k++; } } else { b_p = TRUE; exitg1 = 1U; } } while (exitg1 == 0U); EMLRTPOPRTSTACK(&uc_emlrtRSI); if (b_p) { b_p = TRUE; } else { b_p = FALSE; } EMLRTPOPRTSTACK(&tc_emlrtRSI); if (!b_p) { } else { p = TRUE; } EMLRTPOPRTSTACK(&sc_emlrtRSI); EMLRTPOPRTSTACK(&pc_emlrtRSI); if (!p) { b_p = TRUE; } else { b_p = FALSE; } if (b_p) { } else { EMLRTPUSHRTSTACK(&qc_emlrtRSI); b_y = NULL; m4 = mxCreateCharArray(2, iv19); emlrtInitCharArray(30, m4, cv9); emlrtAssign(&b_y, m4); error(message(b_y, &n_emlrtMCI), &o_emlrtMCI); EMLRTPOPRTSTACK(&qc_emlrtRSI); } if ((x->size[1] == 1) || (x->size[1] != 1)) { b_p = TRUE; } else { b_p = FALSE; } if (b_p) { } else { EMLRTPUSHRTSTACK(&rc_emlrtRSI); c_y = NULL; m4 = mxCreateCharArray(2, iv20); emlrtInitCharArray(36, m4, cv10); emlrtAssign(&c_y, m4); error(message(c_y, &p_emlrtMCI), &q_emlrtMCI); EMLRTPOPRTSTACK(&rc_emlrtRSI); } if (x->size[1] == 0) { y = 0.0; } else { vlen = x->size[1]; y = x->data[0]; for (k = 2; k <= vlen; k++) { y += x->data[emlrtDynamicBoundsCheck(k, 1, x->size[1], &ee_emlrtBCI) - 1]; } } return y; }