[code]function[Y] = busadmittance(z) ne = z(:,1); nt = z(:,2); r = z(:,3); x = z(:,4); lines = length(ne); buses = max(max(ne), max(nt)); Z = r + 1j*x; y = ones(length(Z),1)./Z; Y = zeros(buses,buses); [/code] How can I vectorize below 'for' loops, that follows the above code?
[code]for k = 1:buses for l = 1:lines if ne(l) == k || nt(l) == k Y(k,k) = Y(k,k)+ y(l); end end end for k = 1:lines if ne(k)>0 && nt(k) > 0 Y(ne(k),nt(k)) = -y(k); Y(nt(k),ne(k)) = -y(k); end end[/code] are there any additional code enhancements apart from preallocation and vectorization, that can greatly affect the performance? (forget gpu, cluster)


JLCPCB – Prototype 10 PCBs for $2 (For Any Color)

China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir