I'm writing a program to compute the determinant of a 2x2 square matrix. It seems to be working fine, but I need to format the determinant result in the system FP(10,4,1). I've tried formatting the matrix inputs in exponential notation but each input is being represented in a different floating point system. For example, if the input matrix is:
A=[[101,101.1],[1.187,1.186]]
I need to convert this matrix to the form:
A1=[[0.0101E+04, 0.1011E+03], [0.1187E+01, 0.1186E+01]].
I've tried formatting using format(num,"e")
, but this way it seems that I cannot control how many decimals should be used to represent each number.
m=2
n=2
mat=[[0 for x in range(m)] for y in range(n)]
print("Digite os termos da matriz:")
for i in range(0,2):
for j in range(0,2):
num=float(input())
#num=num.format_float_scientific(num.float32(num.num))
mat[i][j]=format(num, "e")
print(mat)
#mat[0][0]=mat.format_float_scientific(mat.float32(mat.mat[0][0]))
det=float(mat[0][0])*float(mat[1][1])-float(mat[0][1])*float(mat[1][0])
#det=mat[0][0]*mat[1][1]-mat[0][1]*mat[1][0]
print(det)