3from IPython.display
import Math
4from IPython.display
import display
9 def __init__(self, input_variable_list = []):
12 Variables can be defined at __init__. In that case, insert a list of variables as first argument.
26 if len(input_variable_list) != 0:
35 return copy.copy(self)
39 Select Print Mode (Default : False)
40 False : Print with IPython.Display (Output is in Latex format if a jupyer notebook-based application is used.)
41 True : Print with print function(The output is in Latex formula notation. Pasteable in overleaf or Cloud latex.)
47 Assign left hand side and right hand side
60 Assign right hand side
66 Registor the variables created by sympy.symbol to this class.
67 It is used for differentiating and integrating.
70 if input_list
is not None:
77 Return left hand side and right hand side
89 Return right hand side
95 Create variables as algebra using sympy.symbols
96 input_variable_list : list of variables.
99 for i
in range( len( input_variable_list ) ):
105 def assign_values(self, symbol, values,round_digits=None, update_flag=False ):
107 Assign and round variables.
108 symbol : list of slgebaric variables
109 values : list of numerical variables
110 round_digits : number of digits(default: noround)
111 update_flag : flag for updating original function(default: noupdate)
114 if round_digits
is not None:
115 for i
in range( len( values ) ):
116 values[i] = round( values[i], int(round_digits) )
127 Return registered symbols
133 Return assigned values
139 Improve readability when the formula will be dumped since the default number of digits displayed is very large.
140 The rounded function is overridden by the original function.
141 Therefore, it is recommended to use this function only at the end of the function output.
142 In addition, the problem of +1.0 and -1.0 being displayed after rounding has been eliminated.
143 (+1.0 and -1.0 when rounding with zero digits forces the assignment of +1 and -1.)
148 rounded_matrix = self.
right_hand_side.applyfunc(
lambda x: round(x, round_digits))
153 val = round( n, round_digits )
154 if abs( round( val, 0 ) ) == 1:
155 replacements[n] = int( round( val, 0 ) )
157 replacements[n] = round( n, round_digits )
166 Create matrix as algebra
167 matrixsymbol : variable that represents the entire matrix. (recommend to use capital letter)
168 row : maximum row number
169 col : maximum column number
170 elementsymbol : symbol of each elements (if elementsymbol is none, lowercase letter is adpoted)
175 for i
in range( row ):
176 rowindex =
"_"+str(i+1)
178 for j
in range( col ):
179 colindex =
"_" + str(j+1)
181 if elementsymbol
is None:
182 elements = matrixsymbol.lower() + rowindex+colindex
184 elements = elementsymbol + rowindex + colindex
186 row.append( elements )
194 Select print mode in self.select_print_mode()
195 False : Print with IPython.Display (Output is in Latex format if a jupyer notebook-based application is used.)
196 True : Print with print function(The output is in Latex formula notation. Pasteable in overleaf or Cloud latex.)
199 display( Math( f
'{self.left_hand_side} = {sympy.latex( self.right_hand_side )}' ) )
206 Select print mode in self.select_print_mode()
207 False : Print with IPython.Display (Output is in Latex format if a jupyer notebook-based application is used.)
208 True : Print with print function(The output is in Latex formula notation. Pasteable in overleaf or Cloud latex.)
211 if external_input_lhs
is not None:
212 dum_lhs = external_input_lhs
213 if external_input_rhs
is not None:
215 display( Math( f
'{dum_lhs} = {sympy.latex( external_input_rhs )}' ) )
217 print( dum_lhs,
" = ", sympy.latex( external_input_rhs ),
"\\\\" )
222 assign_flag : flag to update original function. (default : no update)
226 display( Math( f
'{self.left_hand_side} = {sympy.latex( self.expanded_right_hand_side )}' ) )
237 return sympy.Matrix( input )
241 Execute indefinite integral with variable called in 2nd argument.
252 Execute definite integral with variable called in 2nd argument from min(3rd argument) to max(4th argument).
263 Execute differentiate with variable called in 2nd argument.
select_print_mode(self, Bool)
get_variable_symbols(self)
round_right_hand_side(self, round_digits)
definite_integral(self, val, min, max, update_flag=False)
differentiated_right_hand_side
set_right_hand_side(self, rhs)
list matrix_element_symbols
list created_variable_symbols
print_external_input(self, external_input_lhs=None, external_input_rhs=None)
str differentiated_left_hand_side
create_martix_symbols(self, matrixsymbol, row, col, elementsymbol=None)
indefinite_integral(self, val, update_flag=False)
set_left_hand_side(self, lhs)
str integrated_left_hand_side
expand_formula(self, assign_flag=False)
assign_values(self, symbol, values, round_digits=None, update_flag=False)
differentiate(self, val, update_flag=False)
integrated_right_hand_side
set_variable_symbols(self, input_list=None)
get_variable_values(self)
create_variables(self, input_variable_list)
set_formula(self, lhs, rhs)
get_right_hand_side(self)
__init__(self, input_variable_list=[])