GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — CompEconRecompiled/dprod.m at master · LRondina/CompEconRecompiled

Expand file tree

/

dprod.m

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
52 lines (48 loc) · 1.42 KB
/

dprod.m

Copy path

File metadata and controls

52 lines (48 loc) · 1.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
% DPROD Computes the direct product of two matrices.
% USEAGE:
% c=DPROD(a,b)
% The direct sum of two matrices with the same number of rows is
% equivalent to computing row-wise tensor (Kronecker) products.
% Thus DPROD is equivalent to:
% c=[]; for i=1:size(a,1), c=[c;kron(a(i,:),b(i,:))]; end
% or
% n=size(a,2); p=size(b,2); c=a(:,ones(p,1)*(1:n)).*b(:,(1:p)'*ones(1,n));
%
% See Also: KRON, CDPROD, DSUM.
% Copyright (c) 1997 by Paul L. Fackler
function c=dprod(a,b)
if nargin~=2; error('Two arguments must be passed'); end
if isempty(a), c=b;
elseif isempty(b), c=a;
else
[ra,ca]=size(a);
[rb,cb]=size(b);
if ra~=rb
disp([ra rb])
error('a and b must have the same number of rows')
end
if issparse(a) || issparse(b)
[ia,ja,sa]=find(a);
[ib,jb,sb]=find(b);
if ra==1 % due to quirk in MATLAB
ia=ia(:); ja=ja(:); sa=sa(:); % FIND returns a row vector if
ib=ib(:); jb=jb(:); sb=sb(:); % its argument is a row vector
end
nza=length(sa);
nzb=length(sb);
ii=ia';
ii=find(ii(ones(nzb,1),:)==ib(:,ones(nza,1)));
ic=ib(:,ones(nza,1));
ic=ic(ii);
jc=cb*(ja'-1);
jc=jc(ones(nzb,1),:)+jb(:,ones(nza,1));
jc=jc(ii);
sc=sb*sa';
sc=sc(ii);
c = sparse(ic,jc,sc,ra,ca*cb);
else
k=1:ca; k=k(ones(cb,1),:);
l=(1:cb)'; l=l(:,ones(ca,1));
c=a(:,k).*b(:,l);
end
end
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.