Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-11-24, 01:40   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
默认 time multiplying matrices and vectors

I wrote this algorithm that resolves matrix-vector product two ways:
Imagine i have a matrix A nxn and a vector X nx1



1) inner-product: Y11 = A11*X11 + A12*X21 + .... + A1n*n1 and so on



2) lineal combination: Y = Colum1mn*X1 + Column2*X2 and so on



I did this because i wanted to compare who is the fastest way to multiply Matrix-Vector i tried with



n=[10000,9000,8000,7000,6000,5000,4000,3000,2000,1500,1000,800,500,300,100]



run the algorith 3 times and took the average value with every value of n and got this graph, and i was right, inner-product is the fastest because of how is saved matrix in memory thats ok but i ran algorithm 3 times to graph the points and got that Time of N=7000 > time of N=8000 > time of N=9000. And i want to know why is this? i thought that it could be something like the computer will start calculating slowly but if i run the algorithm more times it will calculate faster. But i ran the algorithm 7 times after the first 3 (10 in total) and got about the same result (this time n=7000 time was about 130 sec not 150 but still is time 7000 > time 8000 > time 9000)



This is the code i wrote



def Lineal_C(A,x,n):
y=np.zeros(n)
t = time.clock()
for j in range(n):
for i in range(n):
y[i]=y[i]+A[i][j]*x[j][0]
time_spent = time.clock() - t
print ("%.10f sec" % (time_spent)+" n"+str(n)+" Lineal Combination ")

def Inner_P(A,x,n):
y=np.zeros(n)
t = time.clock()
for i in range(0,n):
for j in range(n):
y[i]=y[i]+A[i][j]*x[j][0]

time_spent = time.clock() - t
print ("%.10f sec" % (time_spent)+" n="+str(n)+" ------MatVectFila - Producto Interno--------")




More...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 03:24


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.