def write_ic_subs(self): all_subs = "" for i, eq in enumerate(self.mm.model_eqs['ic'].sbs.dict['sbs']): eq = str(eq['sym']) + " = " + julia_code( sympify(eq['eq']).subs(self.icd_swap).subs(self.julia_swap)) all_subs += (eq + "\n") for i, eq in enumerate(self.mm.model_eqs['res'].sbs.dict['sbs']): eq = str(eq['sym']) + " = " + julia_code( sympify(eq['eq']).subs(self.icd_swap).subs(self.julia_swap)) all_subs += ("\t" + eq + "\n") return all_subs
def write_icd_list(self, eq_list): """Specialty funciton for writing ICD's in a list format. """ ret = 'T[' for i, eq in enumerate(eq_list): ret += julia_code(eq['eq'].subs(self.icd_swap).subs(self.julia_swap)) if i != len(eq_list)-1: ret += ', ' ret += ']' return ret
def write_res_equations(self): """Specialty funciton for writing RES equations. """ ret = '' for i, eq in enumerate(self.mm.model_eqs['res'].eqs_sym_list): ret += '\t' ret += 'err[{0}] = '.format(i + 1) ret += julia_code(eq['eq'].subs(self.julia_swap)) ret += '\n' ret += '\tnothing\n' ret += 'end\n\n' return ret
def write_rhs_equations(self): """RHS function follow a different formatting for parsing equations. This is their specialized parsing function. """ ret = '' for i, eq in enumerate(self.mm.model_eqs['rhs'].eqs_sym_list): ret += '\t' ret += '_dx[{0}] = '.format(i + 1) ret += julia_code(eq['eq'].subs(self.julia_swap)) ret += '\n' ret += '\tnothing\n' ret += 'end\n\n' return ret
def write_equation_list(self, eq_list): """ Given a list of equations, write them out as a julia array. Parameters ---------- eq_list: ``list`` A list containing equation dictionaries. Where each equation is only on the right-hand side. There should be no symbol for this function. The non-julia values will be subbed with julia values. Example ------- x + b => {"sym": "", "eq": "a + b"} """ ret = 'T[' for i, eq in enumerate(eq_list): ret += julia_code(eq['eq'].subs(self.julia_swap)) if i != len(eq_list)-1: ret += ', ' ret += ']' return ret
def write_substitutions(self, sub_list): """ Given a list of substitutions, write them out prior to the return statement or the main equations. Parameters ---------- sub_list: ``list`` A list containing equation dictionaries. Example ------- c = a + b => {"sym": "c", "eq": "a + b"} """ ret = '' for sub in sub_list: ret += '\t' ret += str(sub['sym']) ret += ' = ' ret += julia_code(sub['eq'].subs(self.julia_swap)) ret += '\n' return ret
A.subs(x1, 0.0).subs(y1, 0.0).subs(x2, 0.0).subs(y2, 1.0).subs(x3, 1.0).subs(y3, 0.0)) print((A * M).subs(x1, 0.0).subs(y1, 0.0).subs(x2, 0.0).subs(y2, 1.0).subs(x3, 1.0).subs(y3, 0.0)) N = [None for i in range(9)] for i in range(3): for j in range(3): N[i + 3 * j] = D * (A[0, i] * A[0, j] + A[1, i] * A[1, j]) N = Matrix(N) print( N.subs(x1, 0.0).subs(y1, 0.0).subs(x2, 0.0).subs(y2, 1.0).subs(x3, 1.0).subs(y3, 0.0)) # B = [x.subs(x1, 0.0).subs(y1, 0.0).subs(x2, 0.0).subs(y2,1.0).subs(x3,1.0).subs(y3,0.0) for x in A] # print(B) s = [None for i in range(9)] for i in range(9): s[i] = julia_code(N[i]) s[i] = s[i].replace(".*", "*").replace(".^", "^").replace("./", "/") s = "T*stack([" + ",".join(s) + "])" print(s) print(julia_code(T).replace(".*", "*").replace(".^", "^").replace("./", "/"))