  MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档 time multiplying matrices and vectors
 用户名 记住信息 密码
 资料存档 资料存档
 主题工具 显示模式 2019-11-24, 01:40 AM #1 高级会员   注册日期: 2019-11-21 帖子: 2,897 感谢他人: 0 有 0 帖获得 0 感谢 声望力: 60  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] 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] time_spent = time.clock() - t print ("%.10f sec" % (time_spent)+" n="+str(n)+" ------MatVectFila - Producto Interno--------") ``` More... ```  主题工具 显示可打印版本 邮寄本页给好友 显示模式 平板模式 切换到混合模式 切换到树形模式 发帖规则 您不可以发表新主题 您不可以发表回复 您不可以上传附件 您不可以编辑自己的帖子 启用 BB 代码 论坛禁用 表情符号 论坛启用 [IMG] 代码 论坛启用 HTML 代码Trackbacks are 禁用 Pingbacks are 禁用 Refbacks are 禁用 版面规则

 -- 简体中文 -- 繁體中文 -- English (US) MATLAB爱好者论坛 - 论坛存档 - 返回顶端 