# Type your text here
defprint_matrice(matrice):n=dim_matrice(matrice)[0]p=dim_matrice(matrice)[1]foriinrange(n):ligne="("forjinrange(p):iflen(str(matrice[i][j]))==1:ligne+=""+str(matrice[i][j])+""eliflen(str(matrice[i][j]))==2:ligne+=""+str(matrice[i][j])+""eliflen(str(matrice[i][j]))==3:ligne+=""+str(matrice[i][j])+""eliflen(str(matrice[i][j]))==4:ligne+=""+str(matrice[i][j])+""else:ligne+=""+str(matrice[i][j])+""ligne+=")"print(ligne)defcrea_matrice(n,p):matrice=[]foriinrange(n):liste=[]foriinrange(p):liste.append(0)matrice.append(liste)returnmatricedefmatrice(n,p):matrice=crea_matrice(n,p)foriinrange(n):forjinrange(p):coeff=int(input("coefficient ligne "+str(i+1)+" colonne "+str(j+1)+" : "))matrice[i][j]=coeffreturnmatricedefdim_matrice(matrice):ifdef_matrice(matrice):return[len(matrice),len(matrice[0])]else:return"Erreur"defdef_matrice(matrice):foriinrange(len(matrice)-1):iflen(matrice[i])!=len(matrice[i+1]):returnFalsereturnTruedefmatrice_diagonale(matrice,n,p):foriinrange(n):forjinrange(p):ifi!=jandmatrice[i][j]!=0:returnFalsereturnTruedefadd_matrice(A,B):ifdim_matrice(A)==dim_matrice(B):C=crea_matrice(dim_matrice(A)[0],dim_matrice(A)[1])foriinrange(dim_matrice(A)[0]):forjinrange(dim_matrice(A)[1]):C[i][j]=A[i][j]+B[i][j]returnCdefmatrice_fois_k(k,matrice):foriinrange(len(matrice)):forjinrange(len(matrice[0])):matrice[i][j]=k*matrice[i][j]returnmatricedefmultiplication_matrice(A,B):ifdim_matrice(A)[1]==dim_matrice(B)[0]:C=crea_matrice(dim_matrice(A)[0],dim_matrice(B)[1])foriinrange(dim_matrice(A)[0]):forjinrange(dim_matrice(B)[1]):S=0S1="C("+str(i+1)+","+str(j+1)+") = "S2="C("+str(i+1)+","+str(j+1)+") = "print("C("+str(i+1)+","+str(j+1)+") = Σ(k=1,"+str(dim_matrice(A)[1])+") a("+str(i+1)+",k)*b(k,"+str(j+1)+")")forkinrange(dim_matrice(A)[1]):S1+="a("+str(i+1)+","+str(k+1)+")*b("+str(k+1)+","+str(j+1)+") + "S2+=str(A[i][k])+"*"+str(B[k][j])+" + "S+=A[i][k]*B[k][j]print(S1[:-2])print(S2[:-2])print("C("+str(i+1)+","+str(j+1)+") = ",S)C[i][j]=Sprint("")print_matrice(C)else:print("le produit matriciel n'est pas définie impossible")deftansposer(matrice):new_matrice=crea_matrice(dim_matrice(matrice)[1],dim_matrice(matrice)[0])foriinrange(dim_matrice(matrice)[0]):forjinrange(dim_matrice(matrice)[1]):new_matrice[j][i]=matrice[i][j]returnnew_matriceprint("bonjour binevenue dans le programme pour calculer une multiplication entre 2 matrice : ")print("")print("")n=int(input("nombre de ligne 1er matrices : "))p=int(input("nombre de colonne 1er matrices : "))print("")A=matrice(n,p)print("")print("")n2=int(input("nombre de ligne 2e matrices : "))p2=int(input("nombre de colonne 2e matrices : "))print("")B=matrice(n2,p2)print("")print("")multiplication_matrice(A,B)
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.