Evaluate
hi @davide_zorzenon : i implement the last task as follows I calculate the example by hand it was correct as the result in code ,I added two more methods so that the code function however I can do it without adding the scalar_to_powerMatrix and do it inside the method Evaluate but I thought we can use it to make the code better as example if we need to multiply two matrixs as powerssries matrixs without making all the elements to strings this can do it . pleas let me know what you think
def scalar_to_powerMatrix(self, matrix):
rows, cols = self.get_deminsion(matrix)
converted_matrix = PowerSeriesMatrix(np.zeros((rows, cols), dtype=object))
for i in range(rows):
for j in range(cols):
converted_matrix[i, j] = PowerSeries(str(matrix[i, j]))
return converted_matrix
def get_deminsion(self, matrix):
rows = 0
cols = 0
while True:
try:
row = matrix[rows, 0]
rows += 1
except IndexError:
break
if rows > 0:
while True:
try:
col = matrix[0, cols]
cols += 1
except IndexError:
break
return rows, cols
def Evaluate(self):
result_matrix = None
for event, matrix in self.mu.items():
event_to_str = PowerSeries(event.name)
rows, cols = self.get_deminsion(matrix)
temp_matrix = PowerSeriesMatrix(np.zeros((rows, cols), dtype=object))
for i in range(rows):
for j in range(cols):
temp_matrix[i, j] = PowerSeries(str(matrix[i, j]) + '(' + event_to_str.series + ')')
print(temp_matrix)
if result_matrix is None:
result_matrix = temp_matrix
else:
result_matrix += temp_matrix
# Convert alpha and beta to PowerSeriesMatrix
print('event_mult_mu is = ' , result_matrix)
alpha_to_pow = self.scalar_to_powerMatrix(self.alpha)
print('alpha is = ', alpha_to_pow)
beta_to_pow = self.scalar_to_powerMatrix(self.beta)
print('beta is = ', beta_to_pow )
result = alpha_to_pow * result_matrix * beta_to_pow
return result