On Monday, August 29, 2016 at 10:02:22 AM UTC-4, Andreas Noack wrote:
>
> Evan, this is exactly where you should use I, i.e.
>
> m = m + λ*I
>
> The reason is that eye(m) will first allocate a dense matrix of 
> size(m,1)^2 elements. Then * will do size(m,1)^2 multiplications of lambda 
> and allocate a new size(m,1)^2 matrix for the result. Finally, size(m,1)^2 
> additions will be computed for the elements in m and lambda*eye(m).
>
> In contrast λ*I will only make a single multiplication, store the result 
> in a tiny stack allocated scalar and only add this to the diagonal of m, 
> i.e. size(m,1) additions.
>
>
Good to know - learn something new ever day! :) 

Reply via email to