Programas de graficación en Phyton
Enviado por JIMENEZ LORA ISRAEL INGENIERIA QUIMICA • 13 de Mayo de 2023 • Examen • 298 Palabras (2 Páginas) • 52 Visitas
[pic 1][pic 2][pic 3][pic 4]
EVALUATIONS U3 NUMERICAL METHODS
[pic 5] Chemical Engineering
Numerical Methods [pic 6] Hérbert Lara Ordaz[pic 7][pic 8]
[pic 9] Israel Jiménez Lora [pic 10] Exercises 11
[pic 11]
The following linear system has a unique solution, implement a program in python and get the solution (show every variable and its value)
All code:[pic 12][pic 13]
Screenshot of results:
[pic 14][pic 15]
[pic 16]
import numpy as blk[pic 17][pic 18][pic 19]
A=blk.matrix([[1,-1,-11,13,-6,13,6,-15,2,-15],
[4,-2,-12,6,-7,1,-8,-6,3,-6],
[-11,12,-8,9,-5,-8,3,8,-1,-6],
[-8,9,8,-3,-6,4,4,-15,4,-2],
[-4,11,11,9,-13,-5,17,-18,13,-5],
[-4,-5,14,-4,13,-8,-15,9,12,-5],
[-15,10,-11,-3,2,1,-10,11,-10,-3],
[-3,-5,-4,-11,1,-13,-6,9,-5,-11],
[-1,1,15,-15,5,14,-9,13,14,5],
[10,-4,-10,-10,8,12,-3,-10,-7,-8]])
B=blk.matrix([[99],[8],[-115],[-213],[-511],[-122],[183],[390],[-85],[484]]) n=10
ReA=A ReB=B
#for i in range (n):
#for j in range (n):
#print ("A[",i,",",j,"]=",A[i,j]) es solo una referencia for i in range (n):
for j in range(n):
#print ("A[",i,",",j,"]=",A[i,j]) es solo una referencia pivote=A[i,i]
if abs(pivote)>0.00001: for j in range(n):
A[i,j]=A[i,j]/pivote B[i]=B[i]/pivote
for j in range (n): if j!=i:
pivote=A[j,i]
for k in range (n): A[j,k]=A[j,k]-pivote*A[i,k]
B[j]=B[j]-pivote*B[i]
else:
if i<n-1:
for j in range (n): aux = A[i,j] A[i,j]=A[i+1,j]
A[i+1,j]=aux aux=B[i] aux=float(B[i]) B[i]=B[i+1]
B[i+1]=aux pivote=A[i,i]
for j in range(n): A[i,j]=A[i,j]/pivote
B[i]=B[i]/pivote for j in range (n):
if j!=i:
pivote=A[j,i]
for k in range (n): A[j,k]=A[j,k]-pivote*A[i,k]
B[j]=B[j]-pivote*B[i]
print(A) print("") print(B) z=10
else:
print("the system has not a singular solution") i=n-1
y=float(B[8]-A[8,9]*z)
x=float(B[7]-A[7,9]*z)
v=float(B[6]-A[6,9]*z)
w=float(B[5]-A[5,9]*z)
s=float(B[4]-A[4,9]*z)
t=float(B[3]-A[3,9]*z)
p=float(B[2]-A[2,9]*z)
q=float(B[1]-A[1,9]*z)
d=float(B[0]-A[0,9]*z) print("")
print("d=",d)
print("q=",q)
print("p=",p)
print("t=",t)
print("s=",s)
print("v=",v)
print("w=",w)
print("x=",x)
print("y=",y)
print("z=",z)
...