Matlab - How to improve efficiency of two port matrix calculations? -


i'm looking way speed simple 2 port matrix calculations. see below code example i'm doing currently. in essence, create [nx1] frequency vector first. loop through frequency vector , create [2x2] matrices h1 , h2 (all functions of f). bit of simple matrix math including matrix left division '\' later, , got result pb [nx1] vector. problem loop - takes long time calculate , i'm looking way improve efficiency of calculations. tried assembling problem using [2x2xn] transfer matrices, mtimes operation cannot handle 3-d multiplications.

can please give me idea how can approach such calculation without need looping through f?

many thanks: svenr

% calculate frequency , wave number vector

f = linspace(20,200,400); w = 2.*pi.*f; 

% calculation each frequency w

for i=1:length(w)     h1(i,1) = {[1, rho*c*k(i)^2 / (crad*pi); 0,1]};    h2(i,1) = {[1, 1i.*w(i).*mp; 0, 1]};    hzin(i,1) = {h1{i,1}*h2{i,1}};    temp_mat = hzin{i,1}*[1; 0];    zin(i,1) = temp_mat(1,1)/temp_mat(2,1);    temp_mat= h1{i,1}\[1; 1/zin(i,1)];    pb(i,1) = temp_mat(1,1); ub(i,:) = temp_mat(2,1); end 

assuming length(w) == length(k) returns true , rho , c, crad, mp scalars , in last line ub(i,1) = temp_mat(2,1) instead of ub(i,:) = temp_mat(2,1);

 temp = repmat(eyes(2),[1 1 length(w)]);  temp1(1,2,:) = rho*c*(k.^2)/crad/pi;  temp2(1,2,:) = (1i.*w)*mp;  h1 = permute(num2cell(temp1,[1 2]),[3 2 1]);  h2 = permute(num2cell(temp2,[1 2]),[3 2 1]);  hzin =  cellfun(@(a,b)(a*b),h1,h2,'uniformoutput',0);  temp_cell = cellfun(@(a,b)(a*b),h1,repmat({[1;0]},length(w),1),'uniformoutput',0);  zin_cell = cellfun(@(a)(a(1,1)/a(2,1)),temp_cell,'uniformoutput',0);  zin = cell2mat(zin);  temp2_cell = cellfun(@(a)({[1;1/a]}),zin_cell,'uniformoutput',0);  temp3_cell = cellfun(@(a,b)(pinv(a)*b),h1,temp2_cell);  temp4 = cell2mat(temp3_cell);  p(:,1) = temp4(1:2:end-1);  ub(:,1) = temp4(2:2:end); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -