def calculation(matrixA, matrixB, type, k, l): try: k, l = [int(k), int(l)] A, Ar, Ac = MATRIX(matrixA) B, Br, Bc = MATRIX(matrixB) if type == "A": anser = LATEX(A) elif type == "B": anser = LATEX(B) elif type == "kA+lB": anser = LATEX(k * A + l * B) type = str(k) + "A+" + str(l) + "B" elif type == "AB": anser = LATEX(A * B) elif type == "BA": anser = LATEX(B * A) elif type == "A・B(内積)": anser = LATEX(B.dot(A)) elif type == "A×B(外積)": anser = LATEX(A.cross(B)) elif type == "B×A(外積)": anser = LATEX(B.cross(A)) anser = str(type) + "=" + anser except: anser = "Error" flash("エラー:もう一度入力してください") return anser
def sysio_matrix(matrix_A, matrix_B, matrix_C, matrix_D, matrix_X, formula, lower_end, upper_end, type): A, Ar, Ac = MATRIX(matrix_A) B, Br, Bc = MATRIX(matrix_B) C, Cr, Cc = MATRIX(matrix_C) D, Dr, Dc = MATRIX(matrix_D) X, Xr, Xc = MATRIX(matrix_X) formula = simplify(formula) lower_end, upper_end = [float(lower_end), float(upper_end)] inverse = (s * eye(Ar) - A).inv() matrix_T = inverse_laplace_transform(inverse, s, t) print(matrix_T) anser_1 = matrix_T * X Integrand = (matrix_T.subs(t, t - τ)) * B * formula T = integrate(Integrand, τ) anser_2 = T.subs(τ, t) - T.subs(τ, 0) anser = LATEX(anser_1 + anser_2) title = str(factor(anser)).replace("Heaviside(", "u_s(") # データ作成 T = np.linspace(lower_end, upper_end, num) Y = np.array([anser.subs(t, T[i]) for i in range(len(T))]) fig = plt.figure(figsize=(7, 4)) plt.plot(T, Y) plt.xlim(lower_end, upper_end) plt.title("$y(t)=" + LATEX(title) + "(" + str(lower_end) + "<t<" + str(upper_end) + ")$") # canvasにプロットした画像を出力 canvas = FigureCanvasAgg(fig) png_output = BytesIO() canvas.print_png(png_output) data = png_output.getvalue() # HTML側に渡すレスポンスを生成する response = make_response(data) response.headers['Content-Type'] = 'image/png' response.headers['Content-Length'] = len(data) return response
def calculation(matrixA, Ar, Ac, type): try: Ar, Ac = [int(Ar), int(Ac)] A = MATRIX(matrixA, Ar, Ac) if type == "A": anser = LATEX(A) elif type == "A^n": A = list(A.diagonalize()) P = A[0] D = A[1] for i in range(0, Ac, 1): D[i, i] = "(" + str(D[i, i]) + ")^n" anser = LATEX(P * D * P.inv()) elif type == "A^t": anser = LATEX(A.transpose()) elif type == "A^{-1}": anser = LATEX(A.inv()) elif type == "\widetilde{A}": anser = LATEX(A.adjugate()) elif type == "det(A)": anser = LATEX(A.det()) elif type == "rank(A)": anser = LATEX(A.rank()) elif type == "tr(A)": anser = LATEX(A.trace()) elif type == "λ": A = A.eigenvals() anser = "" for B in A.items(): anser += LATEX(B[0]) + "(n=" + LATEX(B[1]) + "), " elif type == "P": A = A.diagonalize() A = list(A) anser = LATEX(A[0]) elif type == "P^{-1}AP": A = A.diagonalize() A = list(A) anser = LATEX(A[1]) except: anser = "Error" flash("エラー:もう一度入力してください") return anser
def calculation(matrixA, type): try: A, Ar, Ac = MATRIX(matrixA) if type == "A": anser = "A="+LATEX(A) elif type == "A^n": if(Ar == Ac): P, D = list(A.diagonalize()) for i in range(Ac): D[i, i] = "("+str(D[i, i])+")^n" anser = "A^n="+LATEX(P*D*P.inv()) else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" elif type == "A^{-1}": if(Ar == Ac): anser = "A^{-1}="+LATEX(A.inv()) else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" elif type == "A^t": anser = "A^T="+LATEX(A.transpose()) elif type == "\widetilde{A}": if(Ar == Ac): anser = "\widetilde{A}="+LATEX(A.adjugate()) else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" elif type == "det(A)": if(Ar == Ac): anser = "det(A)="+LATEX(A.det()) else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" elif type == "rank(A)": anser = "rank(A)="+LATEX(A.rank()) elif type == "tr(A)": if(Ar == Ac): anser = "tr(A)="+LATEX(A.trace()) else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" elif type == "λ": if(Ar == Ac): A = A.eigenvals() anser = "" for B in A.items(): anser += ("\lambda="+LATEX(B[0])+"(n="+LATEX(B[1])+"), ") else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" elif type == "P": if(Ar == Ac): A = list(A.diagonalize()) anser = "P="+LATEX(A[0]) else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" elif type == "P^{-1}AP": if(Ar == Ac): A = list(A.diagonalize()) anser = "P^{-1}AP="+LATEX(A[1]) else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" elif type == "Φ(t)": if(Ar == Ac): anser = "Φ(t)="+LATEX((s*eye(Ar)-A).inv()) else: flash("Error:正方行列を入力してください") anser = "正方行列を入力してください" except: anser = "Error" flash("エラー:もう一度入力してください") return anser
def Homogeneous(matrixA): A, Ar, Ac = MATRIX(matrixA) T = calcT_2(A) anser = "^{0}T_{" + str(T.shape[0] - 1) + "} = " + LATEX_M(T) return anser